【问题标题】:Git, SSH and ProxyCommandGit、SSH 和 ProxyCommand
【发布时间】:2013-06-11 17:26:44
【问题描述】:

我有一个位于防火墙后面的 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.

origin repo 的 url 是

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

我认为我已经完成了大部分工作,但缺少一个关键的小部分。任何指向我可能做错了什么的指针?

【问题讨论】:

    标签: git ssh proxy


    【解决方案1】:
    ssh://user_git_server@git_server.dom/path/to/bare/repository/repo.git
                          ^^^^^^^^^^^^^^
    

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

    正确的网址应该是

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

    或者干脆

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

    【讨论】:

    • 不,这也可以。它是一个ssh-uri,即一个非scp syntax,它不会使用~/.ssh/config 文件。如果您按照建议使用scp syntax,则无需指定用户名:ssh://git_server:/path/to/bare/repository/repo.git。你的意思是'colon',而不是“颜色”;)
    • 我不确定究竟是什么让你说“不”。 ssh-uri 什么时候不使用 ssh-config 文件?
    • 啊。测试了这个,冒号必须去。
    • 我的意思是“不,OP 没有使用错误的 url,只是一种不同的语法,它不会利用 ssh 配置文件”。
    • 好吧,在这种情况下,您似乎错了。至少我的 ssh 不关心语法,会一直使用我的配置文件。
    【解决方案2】:

    如“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
    

    【讨论】:

      猜你喜欢
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 2014-04-06
      • 1970-01-01
      相关资源
      最近更新 更多