解决 Github 无法登录的问题

3,551 阅读1分钟

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

问题复现

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

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 过程中报错:

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查询网站: www.ipaddress.com/

  • 查询 github.com

  • 保存结果

  • 查询 github.global.ssl.fastly.net

  • 保存结果

写入host文件

  • Windows

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

# github
140.82.112.4 github.com
199.232.69.194 github.global.ssl.fastly.net

# github
192.30.253.112 github.com 
151.101.185.194 github.global.ssl.fastly.net

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

打开\etc\hosts

# github 
140.82.112.4 github.com
199.232.69.194 github.global.ssl.fastly.net

# github
192.30.253.112 github.com 
151.101.185.194 github.global.ssl.fastly.net

# github
192.30.255.112  github.com git 
185.31.16.184 github.global.ssl.fastly.net

刷新DNS

  • Windows

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

ipconfig /flushdns
  • Linux

在终端中输入:

sudo rcnscd restart

重启浏览器即可访问 github

解决方案二

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