git pull encounters kex_exchange_identification: Connection



当我使用git pull从GitHub拉代码时,我遇到了以下错误:

kex_exchange_identification: Connection closed by remote host
Connection closed by 20.205.243.166 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我确信这个ssh密钥工作得很好,直到昨天,但我不知道为什么这个错误发生。我的笔记本电脑是Macbook Air 13, Monterey 12.4。有人能帮我吗?非常感谢。

我尝试ssh -vT git@github.com调试,但似乎没有错误。我不知道怎么处理,有人能帮我吗?非常感谢。以下是ssh -vT git@github.com输出的msg(用户名替换为${username})

OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/${username}/.ssh/config
debug1: /Users/${username}/.ssh/config line 7: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/${username}/.ssh/id_github_rsa type 0
debug1: identity file /Users/${username}/.ssh/id_github_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
kex_exchange_identification: Connection closed by remote host
Connection closed by 20.205.243.166 port 22

您可以执行以下两个步骤来求解

  1. 删除本地~/.ssh目录,重新生成keygen,并粘贴到GitHub:
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
ssh-keygen -t rsa -C "youremail@example.com"

打开~/.ssh/id_rsa.pub(winC:Usersname.sshid_rsa.pub)复制内容

转到GitHub SSH和GPG密钥,创建一个新的SSH keys粘贴内容并保存

测试:

ssh -T git@github.com

显示Hi username! You've successfully authenticated, but GitHub does not provide shell access.是好的

如果仍然存在Connection closed by 20.205.243.166 port 22,则执行步骤2

  1. 添加配置

创建/修改~/.ssh/config文件,添加以下代码:

Host github.com
HostName ssh.github.com
User git
Port 443

如果超时,请重新使用VPN全局

确保你没有连接到VPN,或者如果你是,确保它不是在增强模式。

在我的情况下,我将ProxyCommand nc -v -x 127.0.0.1:7890 %h %p添加到~/.ssh/config,然后它工作…

配置内容
Host github.com
HostName github.com
User yourUsername
IdentityFile ~/.ssh/id_rsa_github
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p

如果您使用VPN,那么问题很可能是您没有启用终端代理。

打开终端代理,问题成功地解决了。我用的是macOS系统。在macOS中,浏览器代理的成功并不意味着终端代理的成功。例如,我的代理端口是7890,我运行以下命令:

export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

我在我的~/上添加了Git的主机名。Ssh/config,这解决了我的问题。当我遇到和你一样的问题时,我正在使用VPN。

Host github.com
Hostname ssh.github.com
Port 443

相关内容

  • 没有找到相关文章

最新更新