gpt4 book ai didi

Git、SSH 和 ProxyCommand

转载 作者:太空狗 更新时间:2023-10-29 12:54:49 25 4
gpt4 key购买 nike

我有一个在防火墙后面的 git 服务器。我可以从家里访问防火墙,但不能访问 git 服务器。但是,我可以从防火墙访问 git 服务器(也就是说,我可以 SSH 到防火墙,然后再从防火墙 SSH 到 git 服务器)。我希望从我的家用机器上推送和 pull git 存储库,我认为 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.

原始仓库的 url 是

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

我认为我已经准备好大部分内容,但缺少一个关键的小部分。关于我可能做错了什么的任何指示?

最佳答案

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

关于Git、SSH 和 ProxyCommand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17119058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com