runsisi's

technical notes

git clone ssh repo 时使用 http 代理

2019-07-10 runsisigit

方法一

$ sudo vi /etc/ssh/ssh_config

Host gerrit.zte.com.cn
    # ProxyCommand nc --proxy 192.168.5.2:3334 %h %p
    proxycommand socat - PROXY:192.168.5.2:%h:%p,proxyport=3334

方法二

$ vi git-ssh.sh
ssh -o "proxycommand socat - PROXY:192.168.5.2:%h:%p,proxyport=3334" $*
# ssh -o StrictHostKeyChecking=no -o "proxycommand socat - PROXY:192.168.5.2:%h:%p,proxyport=3334" $* 
# ssh -o StrictHostKeyChecking=no -F /dev/null -i /path/to/private_key -o "proxycommand socat - PROXY:192.168.5.2:%h:%p,proxyport=3334" $*

GIT_SSHGIT_SSH_COMMAND 的使用与 git 版本有关,请参考 使用指定 ssh 私钥访问 git 仓库

$ chmod +x git-ssh.sh
$ GIT_TRACE=1 GIT_SSH=./git-ssh.sh git clone ssh://runsisi@git.example.com:2222/ceph/ceph

参考资料

使用指定 ssh 私钥访问 git 仓库

https://runsisi.com/2019-04-23/git-ssh-clone

Connect with SSH through a proxy

https://stackoverflow.com/questions/19161960/connect-with-ssh-through-a-proxy

Passing ssh options to git clone

https://stackoverflow.com/questions/7772190/passing-ssh-options-to-git-clone