码农之家

警告:远程主机标识已更改!

问题

好久没有更新 👉blog ,今天更新了一篇文章,发现推送到 github 上的时候,显示了一个告警信息,导致推送失败,具体原因如下:

我是使用的ssh,跟远程仓库链接

PS D:\mine-project\blog> git push
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:uNiVztksCs=========czCvj3tD2s.
Please contact your system administrator.
Add correct host key in /c/Users/xiao/.ssh/known_hosts to get rid of this message.       
Offending RSA key in /c/Users/xiao/.ssh/known_hosts:5
RSA host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
PS D:\mine-project\blog>

原因

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

警告:远程主机标识已更改!

此报错是由于远程的主机的公钥发生了变化导致的。

ssh服务是通过公钥和私钥来进行连接的,它会把每个曾经访问过计算机或服务器的公钥(public key),记录在~/.ssh/known_hosts 中,当下次访问曾经访问过的计算机或服务器时,ssh就会核对公钥,如果和上次记录的不同,OpenSSH会发出警告。

解决

  1. 使用命令清除所连接的IP或域名
ssh-keygen -R XX.XX.XX.XX (或者域名)
PS C:\Users\xiao\.ssh> ssh-keygen -R github.com
# Host github.com found: line 5
C:\Users\xiao/.ssh/known_hosts updated.
Original contents retained as C:\Users\xiao/.ssh/known_hosts.old
PS C:\Users\xiao\.ssh>

执行完这条命令,就会删除 known_hosts文件里的关于 github.com的记录

  1. 当重新链接 github.com 的主机时,会重新生成指纹,建立链接。
PS D:\mine-project\blog> git push
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMX======YWeIOttrVc98/R1BU======gUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

打开 known_hosts文件,可以看到以及重新添加了github的记录

关于SSH更多请点击:常用的SSH,你了解多少?


我是 甜点cc,个人网站(国外站点): blog.i-xiao.space/

公众号:【看见另一种可能】

原文链接:https://juejin.cn/post/7238886731059249207 作者:甜点cc