33人参与 • 2025-09-28 • 其他编程
(啪!)当你满心欢喜打开ubuntu准备推送代码时,突然发现终端里的git push卡成狗,浏览器里的github页面直接变成"whoa there!"警告页面。这种时候不要慌(虽然我懂你的血压正在飙升),先来几个灵魂拷问:

当你在地址栏输入github.com后:
$ git clone https://github.com/xxx/yyy.git 正克隆到 'yyy'... fatal: 无法访问 'https://github.com/xxx/yyy.git/':failed to connect to github.com port 443: 连接超时
whoa there! you have triggered an abuse detection mechanism...
(这个最头疼!说明你的ip可能被github暂时拉黑了)
(重要)80%的访问问题都是dns搞的鬼!打开终端:
# 先清空dns缓存 sudo systemd-resolve --flush-caches # 测试解析是否正常 dig github.com +short
如果返回的是127.0.0.53这种本地地址,马上修改dns:
sudo nano /etc/resolv.conf
把内容改成:
nameserver 8.8.8.8 nameserver 1.1.1.1
(ctrl+x保存退出后记得重启网络服务)
同时测试两种协议:
# https测试 curl -v https://github.com -o /dev/null # ssh测试 ssh -t git@github.com
如果只有其中一种协议能通,建议临时切换协议:
git config --global url."git@github.com:".insteadof "https://github.com/"
获取最新ip(这个方法可能需要定期更新):
# 获取实时ip(可能需要科学上网)
curl https://websites.ipaddress.com/github.com | grep -eo '([0-9]{1,3}\.){3}[0-9]{1,3}'
sudo nano /etc/hosts
添加类似这样的记录:
140.82.121.4 github.com 185.199.108.154 github.global.ssl.fastly.net
(注意!ip地址可能变化,建议通过https://www.ipaddress.com/实时查询)
当主站完全无法访问时,试试这些镜像:
# 官方镜像(速度较慢但稳定) git clone https://github.com.cnpmjs.org/用户/仓库.git # 企业级镜像(推荐) git clone https://gitclone.com/github.com/用户/仓库.git
如果以上方法都失效,可以考虑设置git代理:
# 设置http代理(需要先有可用代理端口) git config --global http.proxy http://127.0.0.1:1080 # 设置https代理 git config --global https.proxy https://127.0.0.1:1080
(温馨提示:用完记得取消代理设置!)
编辑ssh配置文件:
nano ~/.ssh/config
添加:
host github.com
hostname ssh.github.com
port 443
user git
(这个神操作可以绕过某些网络限制)
当出现"whoa there"警告时:
# 创建自动检测脚本 echo '#!/bin/bash ping -c 1 github.com > /dev/null || notify-send "github不可用!" ' > ~/github_monitor.sh # 添加定时任务 (crontab -l ; echo "*/5 * * * * ~/github_monitor.sh") | crontab -
# 调整tcp参数 sudo sysctl -w net.ipv4.tcp_syn_retries=3 sudo sysctl -w net.ipv4.tcp_synack_retries=3
(知其然更要知其所以然)
最后提醒大家:当github抽风时,正是你站起来活动身体的好时机!(毕竟程序员最缺的就是运动)如果这篇指南帮你解决了问题,不妨…(啊不能引流)那就给自己倒杯咖啡庆祝下吧!
以上就是在ubuntu上打不开github的完整解决方法的详细内容,更多关于ubuntu上打不开github的资料请关注代码网其它相关文章!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论