相信很多网友都遇到过这个问题,而产生的原因也有很多,博主这里简述下本人遇到的问题,以及解决方案,希望对您有帮助~

报错如下

$ git clone git@github.com:ximury/Web.git
Cloning into 'Web'...
kex_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 clone 时选择的是SSH链接,使用HTTPS链接地址进行下载就可以啦!


补充

如何正常使用git协议

1、首先,生成ssh key

ssh-keygen -t rsa -C 'xxxxx@163.com' -f ~/.ssh/github_id_rsa

2、将上述文件对应的公钥文件添加到GitHub平台上(不再详述)

3、验证连接性

ssh -T git@github.com

4、但是,开发者往往有很多git账号,有GitHub的,有GitLab的,有Gitee的,这时候就需要config文件进行配置。

~/.ssh目录下新建config文件

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_rsa

进行验证:ssh -Tv git@github.com

5、如果出现 kex_exchange_identification: Connection closed by remote host 报错信息,可尝试如下方式:

ssh -T git@github.com -p 22

本人指定端口号22,就可以啦!为了方便,可以在config文件里加上Port,如下:

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 22

6、config文件中添加Port后,再次通过git协议进行git pullgit push时,一切正常!

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐