我有一个设置,我们使用堡垒/跳转主机来访问远程服务器,但我在执行 git 克隆时遇到了问题。
在我的 git 配置中,我有以下设置:
本地.ssh/config
Host *.remotedomain.org
ProxyCommand ssh -l username jumphost nc %h 22`
LogLevel DEBUG1
远程.ssh/config
LogLevel DEBUG1
因此,如果我执行 ssh remoteDevel.remotedomain.org
,它将通过该代理主机路由我,一切正常。
案例 1 - 在远程端克隆
#Log into remote machine via SSH
ssh remoteDevel
#Clone repo
git clone ssh://git@stash.remotedomain.org:7999/mirror/disjockey.git
我注意到 SSH 调试“东西”打印出这一行
Initialized empty Git repository in /home/USER/disjockey/.git/
debug1: Executing proxy command: exec /usr/bin/sss_ssh_knownhostsproxy -p 7999 stash.remotedomain.org
在我看来,这就像它在 Atlassian Stash 服务器中创建代理以 pull 下 git 存储库(好)
案例 2 - 通过代理本地
当我在本地尝试相同的命令时出现问题
git clone ssh://git@stash.remotedomain.org:7999/mirror/disjockey.git
首先我看到它试图通过最跳跃的地方
debug1: Executing proxy command: exec ssh -l USERNAME jumphost nc stash.remotedomain.org 22
....
#Lots of junk
....
debug1: Next authentication method: password
git@stash.remotedomain.org's password:
那么呢?
很明显它没有像我希望的那样工作。据我所知,我的代理命令可能已关闭,因为当我在本地运行它时它看起来试图代理到 stash:22
并在我运行时代理到 stash:7999
远程。
我试图将我的代理命令更改为:
ProxyCommand ssh -l username jumphost nc %h 7999
但那似乎永远无法正确登录。不确定在这里做什么,但我假设它可能是我遗漏的一些简单的东西?
更新 SocksProxy
我找到了一种让事情正常进行的方法 - 但我对这实际上有什么帮助感到困惑
首先,我创建了一个 Socks 代理:ssh -D 1080 machine.remotedomain.org
然后我编辑我的.ssh/config
#Host *.remotedomain.org
# ProxyCommand ssh -l username jumphost nc %h 22`
# LogLevel DEBUG1
Host stash.remotedomain.org
User git
ProxyCommand nc -x localhost:1080 %h %p
然后我的 git clone
将工作,但是,这是有问题的,因为我必须在第一个地方注释掉我需要的行来创建我的 socks 隧道。
最佳答案
我们开始工作了!这是成功的 .ssh/config
。
主机远程连接到远程网络上的机器gen1
。
连接到:stash.remotedomain.org 基本上在远程 上面做第二个代理,并代理到端口 7999
是 git 服务器(atlassian stash)正在运行的。
Host remote
HostName gen1
ProxyCommand ssh -l username jumphost nc %h %p
Host stash.remotedomain.org
ProxyCommand ssh remote nc stash 7999
所以当我这样做时:git clone ssh://git@stash.remotedomain.org:7999/mirror/disjockey.git
一切正常!!
关于通过 SSH 代理主机的 git clone 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32654857/