使用git拉取代码时,遇到这个问题
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for gitlab.317hu.com has changed,
and the key for the corresponding IP address 116.62.31.5
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 ECDSA key sent by the remote host is
SHA256:rctUfjaKTvGkv1u/lGCGFf1Ldl8NRAJOCTEAwR3XjGM.
Please contact your system administrator.
Add correct host key in /Users/wanggang/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/wanggang/.ssh/known_hosts:1
ECDSA host key for gitlab.317hu.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.
ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。当下次访问相同计算机时,会核对公钥。如果公钥不同,ssh会发出警告,避免你受到DNS Hijack之类的攻击。因此我们现在只需要删除knows_hosts文件中所对应的公钥即可
解决:第一种方案
1、ssh-keygen -F 计算机名称(IP)
###例如我的错误:我使用如下
ssh-keygen -F gitlab.317hu.com
2、得到gitlab.317hu.com的公钥,以及在所在的行数
# Host gitlab.317hu.com found: line 1
gitlab.317hu.com,172.16.150.202 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBN+VIPYC1TfkW7kKAPBPd8i7deAc91v+X2CJC9i3Q167JYcZKr661X7saLMWRNThMT+AICqdZc4H0fClgTRVTJA=
wanggangdeMacBook-Pro:111 wanggang$
3、去known_hosts中找到对应的公钥将其删除
第二种解决方案:
粗暴点,直接删除known_hosts文件,重新生成一个
1、删除旧的
2、执行下面命令, 一路回车,不用设置密码
ssh-keygen -t rsa -C "wanggang@317hu.com(你自己的账号)"
如上图,就已经创建成功
3、查看公钥,输入命令,得到公钥
cat ~/.ssh/id_rsa.pub
4、复制,粘贴到下图key里即可
参考:
https://blog.csdn.net/xw13106209/article/details/6855294
http://www.anheng.com.cn/news/30032.html
网友评论