突然git clone报错了,之前没遇到过,记录一下

报错信息:

ssh: connect to host github.com port 22: Connection timed out
Please make sure you have the correct access rights
and the repository exists.

运行以下命令检查ssh是否能够连接成功

ssh -T git@github.com

报错:

$ ssh -vT git@github.com
OpenSSH_9.2p1, OpenSSL 1.1.1t  7 Feb 2023
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [20.205.243.166] port 22.
debug1: connect to address 20.205.243.166 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out

这个错误消息表明计算机无法通过 SSH 连接到 GitHub。 "Connection timed out" 意味着连接超时。

检查一下是否添加了SSH密钥

cat ~/.ssh/id_rsa.pub

输出显示已经配置密钥了。

查阅资料后,解决问题方案如下:

在 C:\Users\Username\.ssh 目录下,新建config文件,内容如下:

 

Host github.com
User xxx@xxx.com(你的邮箱)
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

配置完成后,再次执行ssh -T git@github.com
输出如下,输入yes即可

The authenticity of host '[ssh.github.com]:443 ([192.30.255.123]:443)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ssh.github.com]:443,[192.30.255.123]:443' (RSA) to the list of known hosts.

再次运行ssh -T git@github.com就连接上了

Logo

一起探索未来云端世界的核心,云原生技术专区带您领略创新、高效和可扩展的云计算解决方案,引领您在数字化时代的成功之路。

更多推荐