解决 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

可以看到请求到了本地端口,这时想起来本机用了Steamcommunity 302对github.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

- 本文作者:Nine
- 本文链接:https://blog.nine.gt.tc/2025/10/09/git-connection-refused/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)