GitHub Port 22 Timeout - Complete Solution Guide
问题介绍
笔者返校后,突然发现自己git push失败了,显示端口22超时。经过多方搜查,发现是GitHub将笔者所在地屏蔽了。幸甚至哉,还是有许多解决方法的
问题分析
问题自查
在终端或git bash中输入以下命令:
ping github.com
如果出现以下错误:
bash
请求超时。
请求超时。
请求超时。
请求超时。请求超时。
请求超时。
请求超时。
请求超时。再到ITDOG中输入github.com或github.com:22,当你看到你所在地标红
则说明你也中奖了
问题解决
方法一:修改hosts文件
在IPADRESS中输入github.com&github.global.ssl.fastly.net,找到IP地址,并复制(后者可能有多个IP,任选其一即可)
bash
notepad C:\Windows\System32\drivers\etc\hostsnotepad C:\Windows\System32\drivers\etc\hosts或打开文件夹C:\Windows\System32\drivers\etc,找到hosts文件,用记事本打开,在文件末尾添加自己找到的IP地址:
bash
140.82.114.4 github.com
151.101.1.194 github.global.ssl.fastly.net140.82.114.4 github.com
151.101.1.194 github.global.ssl.fastly.net若无法修改文件,可以右键hosts文件,选择属性,在安全中选择高级,在所有者中选择编辑,在组或用户名中选择管理员,在权限中选择完全控制&修改,点击确定
方法二:改变git代理
bash
git config --global http.proxy http://127.0.0.1:7890 # 7890是代理端口,可以自己设置
git config --global http.proxy http://127.0.0.1:7890 # 7890是代理端口,可以自己设置git config --global http.proxy http://127.0.0.1:7890 # 7890是代理端口,可以自己设置
git config --global http.proxy http://127.0.0.1:7890 # 7890是代理端口,可以自己设置可以通过以下命令查看代理是否生效:
bash
git config --global --get http.proxy
git config --global --get https.proxygit config --global --get http.proxy
git config --global --get https.proxy测试你的解决方案
测试 SSH 连接
bash
# 简单测试
ping github.com # 后续发现方法二不能使用这种测试,因为ping是不接受http代理的
# 测试基本连接
ssh -T git@github.com # 若出现Hi Panchant! You've successfully authenticated, but GitHub does not provide shell access.则说明成功
# 使用详细输出测试
ssh -vT git@github.com
# 简单测试
ping github.com # 后续发现方法二不能使用这种测试,因为ping是不接受http代理的
# 测试基本连接
ssh -T git@github.com # 若出现Hi Panchant! You've successfully authenticated, but GitHub does not provide shell access.则说明成功
# 使用详细输出测试
ssh -vT git@github.com
总结
GitHub 端口 22 超时问题是常见的,但可以解决。目前笔者的方法就是更改host文件
如需额外帮助,请查看 GitHub SSH 故障排除指南 或 GitHub 支持。
如有其他方法,可以在评论区留言或邮箱联系,笔者会及时更新,感激不尽!
祝编程愉快!🚀
Comments