github push 代码 Connection refused 解决办法

By 刘志军 , 2022-05-25, 分类: 其它

github

前段时间gitee将所有开源的仓库改成需要审核才能重新开源这个事在国内程序员圈子内还引起来不小的动静,不过对我来说倒没什么影响,开源的项目基本都放在GitHub,gitee就挂了几个私有仓库。

尽管GitHub访问不方便,但依然阻挡不了大家对GitHub的热爱,毕竟这里是全球程序员的智慧结晶。

对于GitHub经常被墙的事,我发现有时候即时用科学上网还是会出现 Connection refused 的错误,特别是在push代码的时候会出现,这就很影响写代码的心情。

>git push origin main
ssh: connect to host ssh.github.com port 443: Connection refused
fatal: Could not read from remote repository.

然后浏览器访问 GitHub.com 网站又是正常的,我估计是域名解析被污染了。 于是我想到的一个办法是,先查看ssh.github.com 这个域名对应的ip是哪个?

这个可以直接在 https://ipaddress.com/website/ssh.github.com 查到该ip。

photo_2022-05-25_00-57-48.jpg

我查出来ssh.github.com的IP是 140.82.114.36。

知道ip后,接下来测试下ssh是否可以连上

ssh -T -p 443 git@140.82.114.36
The authenticity of host '[140.82.114.36]:443 ([140.82.114.36]:443)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[140.82.114.36]:443' (ECDSA) to the list of known hosts.
Hi lzjun567 You've successfully authenticated, but GitHub does not provide shell access.

如果看到最后一行 Hi xxxx 就说明没问题。

这时候,找到当前用户目录下的.ssh/config 文件,如果没有就自己建一个。只要将Hostname ssh.github.com换成ip地址140.82.114.36即可

Host github.com
Hostname 140.82.114.36
Port 443

最后重新push代码,大功告成

>git push origin main
Enumerating objects: 40, done.
Counting objects: 100% (40/40), done.
Delta compression using up to 4 threads
Compressing objects: 100% (28/28), done.
Writing objects: 100% (28/28), 4.15 KiB | 849.00 KiB/s, done.
Total 28 (delta 22), reused 0 (delta 0), pack-reused 0

赶紧收藏起来吧


关注公众号「Python之禅」,回复「1024」免费获取Python资源

python之禅

猜你喜欢

2024-01-23
解决GitHub代码push失败,提示 connect to host github.com port 22
2017-11-01
作为GitHub初级用户,如何向GitHub贡献代码
2021-10-22
如何解决阿里云访问Github.com慢的问题