git push失败:ssh:connect to host github.com port 22:Connection timed out

问题描述:ssh:connect to host github.com port 22:Connection timed out

问题原因:可能是网络下修改防火墙的问题,导致阻塞了一些端口

解决方案:

步骤1:

ssh -T git@github.com

作用是验证当前的SSH key是不是正常工作

Hi xxx! You've successfully authenticated, but GitHub does not # provide shell access.

看到上述内容,表示当前的SSH key是正常工作的,若不是正常工作,则需要重新生成并添加SSH key

步骤2:若上述操作成功,则用HTTP协议代替SSH,需要将配置文件中的URL改为HTTP

git config --local -e

在git中输入上述代码,修改:

url = git@github.com:username/repo.git

为:

url = https://github.com/username/repo.git

这样就能push了,不会timeout了。该方法同样适用于gitlab。

原文地址:https://www.cnblogs.com/pupilLZT/p/10085823.html