git pull失败报错ssh: connect to host github.com port 22: Connection timed out Could not read from ……成功解决
·
今天在pull仓库内容的时候,突然报错连接超时:
ssh: connect to host github.com port 22: Connection timed out Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
告诉我SSH 端口 22 被阻塞了,SSH 客户端尝试连接 GitHub 的默认端口 22 时,连接超时。这意味着无法建立到 GitHub 的 SSH 连接,因此无法从远程仓库读取数据。
后来先看了日志:
ssh -vT git@github.com
打印了如下:
OpenSSH_9.7p1, OpenSSL 3.2.1 30 Jan 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [20.205.243.166] port 22.
debug1: connect to address 20.205.243.166 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out
可能是从学校的网络换到家里的网络后,新的网络环境可能有不同的防火墙或代理设置,限制了通过端口 22(SSH 默认端口)进行的连接。
然后网上搜到GitHub 提供的备用端口 443,可以替换一下进行访问(GitHub 提供了一个备用的 SSH 服务器,通常在网络受限的情况下有效):
ssh -T -p 443 git@ssh.github.com
但这个方法我这里没效果,依旧是使用了22端口:
D:\Code\vue>ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
然后就换了一个方法(奏效):
-
打开
~/.ssh/config(详细地址C:\Users\Lenovo\.ssh) -
如果没有config文件,就新建一个,记住在命名时去掉“.txt”后缀,只留“config” -
在config中加入(如果有的话就修改):Host github.com HostName ssh.github.com Port 443 User git -
保存后,后台直接运行:
ssh -T git@github.com然后出现:
Hi Deeraniy! You've successfully authenticated, but GitHub does not provide shell access.然后再次git pull:
好耶!
参考了这篇佬的文章:坑:ssh: connect to host github.com port 22: Connection refused - 知乎
更多推荐




所有评论(0)