github域名与IP变更导致无法推送分支问题的解决

问题

当执行推送命令的时候,出现如下错误:

$ git push fork my_branch

bash 复制代码
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for github.com has changed,
and the key for the corresponding IP address 20.205.243.166
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDh.....
Please contact your system administrator.
Add correct host key in /Users/kemix/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/kemix/.ssh/known_hosts:5
RSA host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。

问题分析

刚开始以为是ssh key的问题,通过命令重新生成了

$ ssh-keygen -t rsa -b 4096 -C "我的邮箱"

然后在github上重新添加新的rsa公钥"id_rsa.pub",依旧没有改善。

看错误内容,貌似是"known_hosts"的锅,打开发现与错误提示一致,是因为github.com的IP变更了(正式因为本人好久没有用github提交代码了,都没有尽早发现)。

问题解决

第一步、在"known_hosts"中删除github.com相关行。

第二步、重新拉取下代码,此步骤主要是为了自动生成最新的github.com项,否则会报如下错误:

bash 复制代码
ssh_exchange_identification: Connection closed by remote host
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。

所以当执行拉取命令,并在提示时,回答yes同意:

$ git pull

bash 复制代码
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.

然后就可以快乐的推送自己的fork分支代码了

思考

所以同样道理,一旦以后遇到诸如域名与IP绑定有变更,而导致类似的ssh连接方式出现问题,关键是在"known_hosts"中删除旧的相关项,重新生成即可。

相关推荐
峰向AI9 小时前
学生党/打工人必备:AI自动把课程视频变成讲义
github
其实防守也摸鱼12 小时前
教育信息技术应用创新---基础软件信息赛
运维·服务器·数据库·github·copilot
与自己和解74113 小时前
使用ssh实现 VScode 直连 ubuntu
vscode·ubuntu·ssh
0xR3lativ1ty15 小时前
AI本地部署工具火热趋势
github
LlmCraft|大模型工程实践16 小时前
14. CI/CD 流水线中集成 Docker:GitHub Actions 自动构建部署
ci/cd·docker·github
hulihutu4416 小时前
拒绝延期、bug、货不对板:2026 管理系统定制开发落地保障手册
github·bug·鸿蒙系统·数据库管理员
隔窗听雨眠17 小时前
活动中台系统慢SQL治理实践:从监控告警到性能优化的全链路方法论
sql·性能优化·github
m4Rk_17 小时前
【论文阅读】Agent 记忆机制(60):MemInsight——让 LLM 自动为历史记忆生成语义索引
论文阅读·人工智能·学习·开源·github
小弥儿1 天前
开源 VoiceStudio,声音克隆|配音|有声书一站式本地完成
学习·开源·github
问天_观心1 天前
大模型微调学习(一)
开发语言·人工智能·学习·语言模型·github