git push失败:Push failed REMOTE HOST IDENTIFICATION HAS CHANGED
最近有一次 git push 时有报错,异常信息如下:
异常信息
Push failed
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 ECDSA key sent by the remote host is
SHA256:LmUqV5cIfDvU2tDCJjX1iwyDnDZ6KflqT+vH7GNYLxk.
Please contact your system administrator.
Add correct host key in /c/Users/yesx/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/yesx/.ssh/known_hosts:14
ECDSA host key for [10.8.4.181]:30773 has changed and you have requested strict checking.
Host key verification failed.
Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
排查思路
异常中的关键信息:Host key verification failed.(主机验证失败),并且提示相关的文件是 /c/Users/yesx/.ssh/known_hosts
,相应的host key 为 [10.8.4.181]:30773 (注: yesx是主机名)
打开 /c/Users/yesx/.ssh/known_hosts 文件,发现确实有报错信息中的host信息
查阅了网络资料,这关乎 ssh 协议的一个安全机制。通过ssh连接到计算机时,会缓存计算机的公钥,等到第二次连接上这台计算机时,会验证这台计算机和之前缓存的公钥是否匹配。如果公钥不同,ssh会发出警告或者直接拒绝连接。这样可以避免你受到DNS Hijack之类的攻击。
而我为什么会遇到这种情况?询问运维人员才知道,该地址是docker拉起的gitlab,由于某些原因导致容器重启了(相当于就是服务器重置),所以导致此问题。
解决方案
解决方法简单粗暴,直接根据异常信息,删除 /c/Users/yesx/.ssh/known_hosts 中提示异常的 host key。
reference:
https://blog.csdn.net/ouyang\_peng/article/details/83115290
还没有评论,来说两句吧...