git pull时报错ssh: connect to host github.com port 22: Connection timed out

1,106 阅读2分钟

之前在GitHub上下载了一个插件,由于最近一段时间没有拉代码,在重新拉代码的时候出现了以下错误

fatal: Could not read fran renote repository. Please make sure you have the correct access rights and the repository exists.

image-20221220104144527.png

找不到仓库。那这肯定不对啊,之前下载好的代码明明没有动过,那不会是作者把仓库删了吧。吓得我赶紧去GitHub上看了一眼,还好仓库还在,那这是为啥呢

image.png

我突然想起来我是用代理访问GitHub,于是又尝试ping了下GitHub发现没有ping通,就去修改host文件,在里面添加了

192.30.253.112 github.com

151.101.88.249 github.global.ssl.fastly.net

刷新了一下DNS 缓存,发现可以ping通GitHub了,又拉了一下代码,出现了这个错误

ssh:connect to host github.ccm port 22: Connection timed out Please make sure you have the correct access and the repository exists.

image-20221220105951692.png

首先尝试使用ssh连接GitHub,发现连接超时

Snipaste_2022-12-20_09-34-54.png

这个原因可能是应为防火墙的修改,阻止了GitHub的端口。

这个问题GitHub文档给出了解决办法 ssh故障排除

有时,防火墙会完全拒绝允许 SSH 连接。 如果无法选择使用具有凭据缓存的 HTTPS 克隆,可以尝试使用通过 HTTPS 端口建立的 SSH 连接克隆。 大多数防火墙规则应允许此操作,但代理服务器可能会干扰。

根据提示,如果可以通过ssh连接到github的443端口,只需要在ssh配置中添加如下配置

Host github.com
Hostname ssh.github.com
Port 443

ssh配置的位置就是你本地存放ssh公钥的位置,一般在C盘的.ssh文件夹中。如果此文件夹中没有config文件,就需要创建一个

image-20221220111837354.png

保存好之后就可以成功拉代码了

image-20221220112007994.png

还有一种办法,既然ssh连接不上,就切换到http连接

只需要运行一下命令

git config --local -e

将url从ssh改为https即可

url = git@github.com:username/repo.git
改为
url = https://github.com/username/repo.git

最后

image.png