[Internet上有大量相同的解决方案,用于为git的下载定义代理隧道,例如this,而所有这些都是通过设置git的https.proxy
和http.proxy
配置。但是当您尝试通过clone
协议尝试push
/pull
/ ssh
等时,这些答案不起作用!
例如,当您尝试克隆git config --global https.proxy socks5://127.0.0.1:9999
时通过设置git clone [email protected]:user/repo.git
,它不会通过定义的sock5隧道!
我尝试过各种方法,但是都没有用!
[如何设置git在使用127.0.0.1:9999
连接时使用本地socks5代理(例如ssh
)?
您需要先定义GIT_SSH_COMMAND
environment variable
在其中,您可以重新定义ssh命令,以便使用袜子代理设置
GIT_SSH_COMMAND
或ssh -D $port_number $hostname
# or
ssh -D $port_number $username@$hostname
(或using a proxycommand nc)
重点是:ssh与socks5代理一起使用后,您可以在ncat on Windows中定义相同的语法,Git将使用正确的GIT_SSH_COMMAND
命令。
您也可以使用本地配置对其进行测试:
ssh
访问了许多页面之后,我终于找到了解决问题的方法:
git -c core.sshCommand='ssh -D 9998 [email protected]' git pull
git -c core.sshCommand='ssh -D 9999 127.0.0.1' git pull
要在Ubuntu上安装# [step 1] create a ssh-proxy
ssh -D 9999 -qCN [email protected]
# [step 2] make git connect through the ssh-proxy
# [current script only]
export GIT_SSH_COMMAND='ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [git global setting]
git config --global core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [one-time only use]
git clone -c=core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"' [email protected]:user/repo.git
# OR [current repository use only]
git config core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
:
connect