git - 如何强制 Git 通过其 ssh 连接使用 socks 代理?
问题描述
互联网上有大量相同的解决方案来为 git 的下载定义代理隧道,就像这个一样,这一切都是通过设置 git 的https.proxy
& http.proxy
config 来实现的。clone
但是当您尝试通过协议/ push
/pull
等时,这些答案不起作用ssh
!
例如,通过设置git config --global https.proxy socks5://127.0.0.1:9999
当您尝试克隆时git clone git@github.org:user/repo.git
,它不会通过定义的 sock5 隧道!
我尝试了各种事情,但没有一个工作!
问题:
如何设置 git 在127.0.0.1:9999
使用连接时使用本地 socks5 代理(例如)ssh
?
解决方案
以前的答案可能有效,但我发现它们过于复杂。
最常见的情况应该是通过 SOCKS5 代理访问公司 git 服务器。在这个例子中:
- Git 服务器:git.evilcorp.com
- SOCKS5 代理:本地主机:11080
在这种情况下配置 git 的最简单方法是为 git 服务器 (~/.ssh/config) 提供一个不错的 SSH 配置:
Host git.evilcorp.com
# Identity file specifies wich SSH key used to access the git server.
Identityfile ~/.ssh/id_rsa
# ProxyCommand does the magic to access the proxy server.
ProxyCommand /bin/nc -X 5 -x 127.0.0.1:11080 %h %p
很酷的细节:DNS 解析是由代理完成的,所以你的机器不需要知道公司的 DNS 服务器。