問題描述: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。
