代理 - 终端和Git使用如何代理

GIT

设置HTTP协议

  • socks5方式
1
2
git config --global http.proxy 'socks5://127.0.0.1:1080' 
git config --global https.proxy 'socks5://127.0.0.1:1080'
  • http方式
1
2
git config --global http.proxy "http://127.0.0.1:6667"
git config --global https.proxy "http://127.0.0.1:6667"
  • 取消设置
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

设置SSH协议

创建文件 ~/.ssh/config 【如果存在可忽略】

1
2
3
4
5
6
7
8
9
10
11
Host bitbucket.org
User git
HostName altssh.bitbucket.org
Port 443
ProxyCommand connect -S 127.0.0.1:1080 %h %p

Host github.com
User git
HostName ssh.github.com
Port 443
ProxyCommand connect -S 127.0.0.1:1080 %h %p%

终端 terminal

打开终端执行下面命令即可,无须重启终端

1
2
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"

设置完后 执行下面命令查看自己的IP

1
curl -i http://ip.cn

有个问题就是设置完代理,上面的命令无法测试自己的IP了,应该是这个地址也同时被墙了。

参考:https://blog.kelu.org/tech/2017/06/19/setting-socks5-proxy.html