最近在 git push 推送代码到 Github 时失败,之前是可以的,错误信息如下:

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

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

执行 ssh -T git@github.com 需要几十秒才响应,结果也是失败

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

查看 ls ~/.ssh 发现都存在

id_ed25519  id_ed25519.pub  known_hosts

解决方法

创建文件 ~/.ssh/config 加入配置信息,需要把 User 替换为你的 Github 的邮箱

Host github.com
User tumobi@163.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519
Port 443

再次执行 git push 如果出现如下错误:

Bad owner or permissions on /home/tumobi/.ssh/config
fatal: Could not read from remote repository.

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

需要更改 ~/.ssh/config 文件权限

chmod 600 ~/.ssh/config

参考链接
https://juejin.cn/post/6903824212629127182
https://sekisuiseien.com/computer/11256/

标签: Git