一、问题描述
最近公司的GitLab服务器,由于其他的同事误删了一些东西,导致GitLab服务器不可用了。尝试各种操作都不能恢复之后,我只好将这台服务器进行系统重装,然后重装GitLab服务器了,接着把之前GitLab 备份好的数据都还原之后。让同事们尝试操作Git,同事反馈说无法进行操作,报错大致如下:
root@ubuntusrv6:/data2/home/XXX/apps/Debug# git pull
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
85:82:b1:XXXX:d2.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:2
remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R xxx.xxx.xxx.xxx (服务器ip地址)
ECDSA host key for xxx.xxx.xxx.xxx (服务器ip地址) has changed and you have requested strict checking.
Host key verification failed.
fatal: The remote end hung up unexpectedly
二、解决问题
2.1 问题原因
用OpenSSH的人都知ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。当下次访问相同计算机时,OpenSSH会核对公钥。如果公钥不同,OpenSSH会发出警告。
原因是我的GitLab服务器重装了系统(清除了与我本地SSH连接协议相关信息),本地的SSH协议信息便失效了。SSH连接相同的ip地址时因有连接记录直接使用失效的协议信息去验证该ip服务器,所以会报错,使用上述命令便可以清除known_hosts里旧缓存文件。
2.2 解决方法
删除xxx.xxx.xxx.xxx (服务器ip地址)的相关rsa的信息即可
在本地机输入一下命令行:
ssh-keygen -R xxx.xxx.xxx.xxx (服务器ip地址)
目的是清除你当前机器里关于你的远程服务器的缓存和公钥信息,注意是大写的字母“R”。
操作截图
root@ubuntusrv6:/data2/home/XXX/apps/Debug# ssh-keygen -R xxx.xxx.xxx.xxx (服务器ip地址)
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
删除成功之后,再操作git即可成功。如下图所示
root@ubuntusrv6:/data2/home/XXX/apps/Debug# ssh-keygen -R xxx.xxx.xxx.xxx
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
root@ubuntusrv6:/data2/home/XXX/apps/Debug# git pull
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
ECDSA key fingerprint is 85:82:b1:XXXX:d2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
remote: Counting objects: 213, done.
remote: Compressing objects: 100% (126/126), done.
remote: Total 213 (delta 118), reused 156 (delta 62)
Receiving objects: 100% (213/213), 4.51 MiB | 9 KiB/s, done.
Resolving deltas: 100% (118/118), completed with 60 local objects.
三、参考链接
- https://www.cnblogs.com/cuizhipeng/p/5329848.html
- https://serverfault.com/questions/321167/add-correct-host-key-in-known-hosts-multiple-ssh-host-keys-per-hostname
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:https://blog.csdn.net/ouyang_peng/article/details/81536396