A(本地计算机) <-> B(跳板服务器) <-> C(git repo仓库所在服务器)
我想要通过B来代理A发送给C的git clone请求而不是用ssh-agent转发。为什么A不直接向C发起请求呢?通常是出于安全或下载速度上的考虑,对于中文用户而言,一般都是GFW(笑,梯子还是没有ssh tunneling裸奔快。
- 设置ssh tunnel
ssh -ND locahost:9999 [proxy_user]@[proxy_hostname] -p [port]- 在.ssh/config设置需要通过ssh tunnel转发的服务器
# .ssh/config
Host github.com
User git
IdentityFile ~/.ssh/github_id_rsa
ProxyCommand nc -x localhost:9999 %h %p- git clone
git clone git@github.com:[username]/[reponame].git
- 在设置ssh tunnel时就设置好对应的git仓库服务器
ssh -NL 9999:github.com:22 [proxy_user]@[proxy_hostname]- git clone
git clone ssh://git@localhost:9999/[username]/[reponame].git
这个更方便些(只需要两条命令,懒人福音)。
A(local machine) <-> B(proxy server) <-> C(git repo server)
I would like to git clone the repo on local machine A instead of ssh-agent forwarding that clones the repo on proxy server B. Why not clone the repo directly on A? Well, for the sake of security or the network latency(download speed). For Chinese users, this is mainly due to GFW.
- setup a tunnel between localhost port and proxy server
ssh -ND locahost:9999 [name]@[hostname] -p [port]- setup .ssh/config
# .ssh/config
Host github.com
User git
IdentityFile ~/.ssh/github_id_rsa
ProxyCommand nc -x localhost:9999 %h %p- git clone
git clone git@github.com:[username]/[reponame].git
Here we only proxy commands to github.com.
- setup a tunnel between localhost port and proxy server that only forward conections to github.com:22
ssh -NL 9999:github.com:22 [proxy_user]@[proxy_hostname]- git clone
git clone ssh://git@localhost:9999/[username]/[reponame].git