【Git学习】 使用SSH登录Git服务器报错:host key for (ip地址) has changed and you have requested strict checking

一、问题描述

最近公司的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

  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

字节卷动

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值