GitHub Connection refused

2025/10/09 GitHub 共 619 字,约 2 分钟

解决 GitHub 拉取代码报错:Could not read from remote repository问题。

1、问题

前几日使用 PyCharm 拉取代码时突然报错:

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

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

简单记录下排查过程

# 检查 SSH 是否能够连接成功
ssh -T git@github.com -v

image-20251009104448436

可以看到请求到了本地端口,这时想起来本机用了Steamcommunity 302github.com进行了代理,是对应的 host 失效了,使用 443 端口测试是正常的。

2、解决

方案一

使用 https 的 443 端口代替,本地增加 ssh 配置:vim ~/.ssh/config

Host github.com
    HostName ssh.github.com
	Port 443
    User git
    IdentityFile ~/.ssh/id_ed25519

官方说明:https://docs.github.com/zh/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

方案二

配合使用UsbEAm Hosts Editor工具修改 github.com host

image-20251009110651504

Search

    Table of Contents