git clone 无法通过 HTTP 开始中继



使用 git 克隆时,我遇到了错误。 下面是命令和错误信息。

[user@linux]$ git clone git@github.com:username/repertory.git
FATAL: failed to begin relaying via HTTP.
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

除了git@github,git clone https://...和 git 克隆 git://...效果很好。所以我想 ssh 协议有问题,然后我检查了 ssh。

[user@linux]$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

看来我可以通过 ssh 协议正确连接到 github。但是通过 ssh 克隆 git 有什么问题?

此错误消息来自 SSHconnect.c

这是一个SSH代理命令 -connect.c,通过SOCKS和https代理建立网络连接的简单中继命令:您可以使用此命令在防火墙之外进行SSH会话。

因此,请检查是否需要这样的连接:如果您在防火墙后面的企业中,则很可能需要它,但在这种情况下,请联系您的 IT 支持团队以检查此类解决方案的有效性/批准。

该错误消息表明,即使是此SSH模式(通过https代理中继(也可能被阻止。

如果您不在企业设置中,并且不需要代理,请从环境变量和git config文件中删除它们(HTTPS(S)/PROXY(。

如果您使用的是代理,许多公司防火墙会阻止在 443 以外的端口上访问CONNECT方法。GitHub 使用主机"ssh.github.com"运行侦听端口 443 的 SSH 服务器。

首先,使用以下各项配置 SSH~/.ssh/config

Host github.com, ssh.github.com
User git
Hostname ssh.github.com
Port 443
ProxyCommand socat - PROXY:localhost:%h:%p,proxyport=3128

在上面的示例中,我假设您在主机localhost和端口3128上运行 Web 代理(例如cntlm(。

您也可以用nc替换socat,或者用略有不同的语法替换connect-proxy

测试方法:

ssh -T git@ssh.github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

然后是:

git clone git@ssh.github.com:username/repository.git

相关内容

最新更新