本文最后更新于:2024年1月22日 晚上

Github有时会出现突然连接失败的问题,有部分情况是地址解析错误导致的,本文介绍此类问题的解决方案。

问题复现

Github本来好好的,说不定啥时候就会报错,报错信息如下:

1
2
3
4
5
Connection to XXXXX port 22: Software caused connection abort
fatal: Could not read from remote repository.

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

此问题也会导致 Hexo 在 hexo d 过程中报错:

1
2
3
4
ssh_dispatch_run_fatal: Connection to 13.250.177.223 port 22: Broken pipe
fatal: sha1 file '<stdout>' write error: Broken pipeiB/s
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly

错误原因

  • 网络不通
  • 本地DNS无法正确解析地址

解决思路

不管你能不能访问,github就在那里,是因为我们网络在dns上找不到当前github 的地址导致的无法登录。

方案一

解决思路是手动找到github网站IP,填入到host中,这样我们在访问时会直接从host中读取IP并访问。

方案二

使用代理工具

解决方案一

查找github IP地址

IP查询网站: https://www.ipaddress.com/

  • 保存结果

  • 保存结果

  • 当前 (2024.1.19)需要通过 ssh 连接 github,还需要查询并添加 ssh.github.com

对应 host 文件

1
2
140.82.112.3  github.com git 
140.82.112.35 ssh.github.com

写入host文件

  • Windows

打开 C:\Windows\System32\drivers\etc 路径下的 hosts文件,加入上述结果:

1
2
3
# github
140.82.112.4 github.com
199.232.69.194 github.global.ssl.fastly.net

1
2
3
# github
192.30.253.112 github.com
151.101.185.194 github.global.ssl.fastly.net

1
2
3
# github
192.30.255.112 github.com git
185.31.16.184 github.global.ssl.fastly.net
  • Linux

打开\etc\hosts

1
2
3
# github 
140.82.112.4 github.com
199.232.69.194 github.global.ssl.fastly.net

1
2
3
# github
192.30.253.112 github.com
151.101.185.194 github.global.ssl.fastly.net

1
2
3
# github
192.30.255.112 github.com git
185.31.16.184 github.global.ssl.fastly.net

刷新DNS

  • Windows

打开命令提示符, 输入指令:

1
ipconfig /flushdns
  • Linux

在终端中输入:

1
sudo rcnscd restart

重启浏览器即可访问 github

解决方案二

  • 开着车,GitHub 连接不上问题彻底解决


文章链接:
https://www.zywvvd.com/notes/tools/git/github-cannot-log-in/github-cannot-log-in/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

解决 Github 无法登录的问题
https://www.zywvvd.com/notes/tools/git/github-cannot-log-in/github-cannot-log-in/
作者
Yiwei Zhang
发布于
2020年7月8日
许可协议