前言

之前一直可以通过git协议推拉自己在github上的仓库代码,突然不行,尝试了一些方法,记录下。


问题

clone自己仓库的代码
$ git clone git@github.com:good2luck/XXX.git

报错:

Cloning into ‘XXX’…
kex_exchange_identification: Connection closed by remote host
Connection closed by 10.21.13.108 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

根据报错可以看出来是连接关闭,需要检查访问权限


解决思路

1、确认项目地址正常

2、确认ssh公钥是配置正确的
配置地址:https://github.com/settings/keys
本机的ssh公钥的位置:~/.ssh/id_rsa.pub

没有ssh公钥的,生成ssh公钥步骤:
ssh-keygen -t rsa -C “yourEmail@example.com
双引号的邮箱改成个人邮箱,一路回车即可。

3、测试git链接
命令行执行:ssh -T git@github.com
报错,仍然不行:
kex_exchange_identification: Connection closed by remote host
Connection closed by 20.205.243.166 port 22

4、尝试切换网络,关闭网络代理,有可能有网络限制或者防火墙

5、删除相关配置,并测试ssh
~/.ssh/known_hosts 中关于github的配置
命令行执行:ssh -T -p 443 git@ssh.github.com

参考:https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
包括常见的错误。

出现提示,进行yes回车

The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+XXX/XXX.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 

出现 Hi good2luck! You’ve successfully authenticated,表示成功。

6、此时进行仓库代码的推拉,成功。


总结

也有建议重新生成ssh的,不是很愿意,比较ssh在不同平台上都有使用。通过以上步骤可以解决。