Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac 设置 Git 代理 #15

Open
JaredCen opened this issue Jun 5, 2019 · 0 comments
Open

Mac 设置 Git 代理 #15

JaredCen opened this issue Jun 5, 2019 · 0 comments

Comments

@JaredCen
Copy link
Owner

JaredCen commented Jun 5, 2019

http/https 协议

设置全局 git 代理。注意这里不需要设置 https.proxyGit Documentation 中没有这个参数。

# 走 ss 代理,其中 socks5 的默认本地端口为 1080
$ git config --global http.proxy socks5://127.0.0.1:1080

# 走 http 代理
$ git config --global http.proxy http://<ip>:<port>

推荐使用 socks5h 协议,速度更快:

$ git config --global http.proxy socks5h://127.0.0.1:1080
  • socks5h:域名由socks服务器解析;
  • socks5:域名由本地解析;

若只针对 https://github.com 设置代理:

$ git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

取消代理:

$ git config --global --unset http.proxy

ssh 协议

$ vim ~/.ssh/config

添加以下内容:

Host <host>

# 走 ss 代理
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

# 走 http 代理
ProxyCommand nc -X connect -x <ip>:<port> %h %p

这里使用了 nc (netcat) 命令,具体的参数解析可以通过 nc -h 查阅。

查看本地 sock5 端口

nmap 是一款网络扫描和主机检测工具,可以用来扫描本地 sock5 占用的端口:

$ nmap localhost

Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-10 15:29 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00023s latency).
Other addresses for localhost (not scanned): ::1
rDNS record for 127.0.0.1: www.fs.com
Not shown: 996 closed ports
PORT     STATE SERVICE
80/tcp   open  http
443/tcp  open  https
1080/tcp open  socks
8090/tcp open  opsmessaging

Nmap done: 1 IP address (1 host up) scanned in 6.50 seconds

PS: 文章首发于 简书 ,欢迎大家关注。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant