突然git clone报错了,之前没遇到过,记录一下
报错信息:
ssh: connect to host github.com port 22: Connection timed outPlease make sure you have the correct access rightsand the repository exists.
运行以下命令检查ssh是否能够连接成功
ssh -T git@github.com
报错:
$ ssh -vT git@github.comOpenSSH_9.2p1, OpenSSL 1.1.1t 7 Feb 2023debug1: Reading configuration data /etc/ssh/ssh_configdebug1: Connecting to github.com [20.205.243.166] port 22.debug1: connect to address 20.205.243.166 port 22: Connection timed outssh: 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.comUser xxx@xxx.com(你的邮箱)Hostname ssh.github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsaPort 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)? yesWarning: Permanently added '[ssh.github.com]:443,[192.30.255.123]:443' (RSA) to the list of known hosts.
再次运行ssh -T git@github.com就连接上了