解决命令行中拉取GitHub代码时出现WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED错误的问题

最近在命令行中拉取GitHub代码时,出现了WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!错误,详情如下:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/xiboliya/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/xiboliya/.ssh/known_hosts:3
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.

这是因为前阶段GitHub出了安全性的问题,所以更换了公钥。导致之前使用ssh协议访问过GitHub的系统缓存的公钥校验失败了。
解决方案就是删除本地缓存的GitHub公钥,删除的方法有几种:

1.命令行删除公钥(推荐)
命令行中执行命令:
ssh-keygen -R github.com
如果出现类似如下的信息,说明删除成功:
# Host github.com found: line 3
/Users/xiboliya/.ssh/known_hosts updated.
Original contents retained as /Users/xiboliya/.ssh/known_hosts.old

2.手动删除公钥
编辑known_hosts文件,并删除github.com开头的一行。
各系统下的路径如下:
Linux系统:/home/username/.ssh/known_hosts
macOS系统:/Users/username/.ssh/known_hosts
Windows系统:C:/Users/username/.ssh/known_hosts
此方法跟方法1的效果相同,只是操作复杂一些。

3.手动删除known_hosts文件(不推荐)
直接删除known_hosts文件。此方法会同时删除其他网站缓存的公钥,所以不推荐。

注:
1.如果对GitHub进行了ip重定向或者代理等,可能需要删除重定向的ip开头的一行才能解决此问题。
2.如果删除了对应的公钥,则重新与GitHub交互时,需要重新信任GitHub。

 

猜你喜欢

转载自blog.csdn.net/chenzhengfeng/article/details/130283125