起因

写完文章和代码提交到GitHub时,提示SSH连接超时了,提交不了。

ssh: connect to host github.com port 22: Connection timed out

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

这下给我整不会了,之前提交都是没问题的,怎么突然就出问题了呢?

排查

用浏览器访问GitHub官网,可以访问,说明目前的网络没有墙掉(有时候会)。

image-20240117153604836

检查SSH连接:

ssh -T git@github.com

然后就是之前显示的报错(

解决

总之遇事不决百度一下,找到以下方法,亲测有效(

具体是改变SSH连接的端口,从22变为443(HTTPs)

  1. 首先进入系统用户目录下的.ssh目录:
cd ~/.ssh
  1. 然后创建一个config文件
vim config
  1. 编辑文件内容(i
Host github.com
User YourEmail(你的邮箱)
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
  1. 然后:wq即可。(顺便复习vim编辑器用法了属于是)

然后再提交就可以了~

参考链接

SSH:连接到主机github.com端口22:连接时间超时 - 天使阿丽塔 - 博客园 (cnblogs.com)

Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”_ssh: connect to host github.com port 22: connectio-CSDN博客