git 报错 kex exchange identification

2023-09-03 · 201 chars · 2 min read

大约一周没有往 github 提交代码,今天 push 的时候发现报错了:

kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 7890
fatal: Could not read from remote repository.

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

网上很多说法,没有看到特别明确的故障原因。我这里大概率是因为机场阻断了 22 端口(或者被 clash 什么的占用了)。

解决办法很简单,编辑 ~/.ssh/config 文件, 把 git 调整到 443 端口:

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

如果还不行,可以重新生成下 ssh 秘钥,参考 github 官方文档

2024-01-09 更新

gitlab 也出现了同样的问题,在 ~/.ssh/config 添加:

Host gitlab.com
    HostName altssh.gitlab.com
    User git
    Port 443
赞赏

微信