Git,SSH和ProxyCommand

问题描述 投票:8回答:2

我有一个防火墙后面的git服务器。我可以从家里访问防火墙,但不能访问git服务器。但是,我可以从防火墙访问git服务器(也就是说,我可以SSH到防火墙,然后SSH从防火墙到git服务器)。我希望从家用机器推送到git repos,我认为SSH ProxyCommand会这样做。所以我在SSH配置文件中添加了以下内容:

Host git_server
 HostName git_server.dom
 User user_git_server
 IdentityFile ~/.ssh/id_rsa
 ProxyCommand ssh firewall exec nc %h %p

Host firewall
 HostName firewall.dom
 User user_firewall
 IdentityFile ~/.ssh/id_rsa

通过这种设置,我可以通过执行ssh git_server直接SSH到git服务器。但是,需要与服务器通信的git命令不起作用。 git remote show origin失败了消息:

ssh: connect to host git_server.dom port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

原始仓库的网址是

ssh://user_git_server@git_server.dom/path/to/bare/repository/repo.git

我想我已经掌握了大部分的东西,但我错过了一个小小的关键部分。我可能做错的任何指示?

git ssh proxy
2个回答
3
投票
ssh://user_git_server@git_server.dom/path/to/bare/repository/repo.git
                      ^^^^^^^^^^^^^^

您使用的存储库错误的URL。由于您的ssh配置文件具有git_server的主机条目,因此您还需要在存储库URL中使用该主机名,否则SSH将不使用ProxyCommand。

正确的URL应该是

ssh://user_git_server@git_server/path/to/bare/repository/repo.git

或者干脆

user_git_server@git_server:/path/to/bare/repository/repo.git

1
投票

正如“Git clone from remote ssh repository - change the machine on the remote network before executing the clone command”中所提到的,您可能在代理服务器上没有命令netcat

您还有another solution with socat,它将使用CONNECT方法与HTTP(S)代理服务器协商,以便为远端的服务器提供干净的管道。见socat

host gh
    user git
    hostname github.com
    port 22
    proxycommand socat - PROXY:your.proxy.ip:%h:%p,proxyport=3128,proxyauth=user:pwd

现在你可以说(例如):

git clone gh:sitaramc/git-notes.git
© www.soinside.com 2019 - 2024. All rights reserved.