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

一、问题描述

最近公司的GitLab服务器,由于其他的同事误删了一些东西,导致GitLab服务器不可用了。尝试各种操作都不能恢复之后,我只好将这台服务器进行系统重装,然后重装GitLab服务器了,接着把之前GitLab 备份好的数据都还原之后。让同事们尝试操作Git,同事反馈说无法进行操作,报错大致如下:

root@ubuntusrv6:/data2/home/app/I16/Android/vendor/xtc/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:58:20:21:a5:da:be:24:e8:14:9a:12:b2: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

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

二、解决问题

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/app/I16/Android/vendor/xtc/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即可成功。如下图所示

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

root@ubuntusrv6:/data2/home/app/I16/Android/vendor/xtc/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/app/I16/Android/vendor/xtc/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:58:20:21:a5:da:be:24:e8:14:9a:12:b2: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.
From xxx.xxx.xxx.xxx:AndroidWatch/spreadtrum/SL8521/I16/Android
   d91345c..25207ca  dev_app    -> origin/dev_app
   5575030..b2a2a6c  dev_bsp_180508 -> origin/dev_bsp_180508
   cfc9fa3..6608107  dev_framework -> origin/dev_framework
   1af4e36..e0f9057  dev_modem  -> origin/dev_modem
   8d1381f..58d31bc  dev_multimedia -> origin/dev_multimedia
   9e87f4e..5e7c43f  dev_performance -> origin/dev_performance
   fb0c735..2ee6e1c  feature/optimized_speaker_shock -> origin/feature/optimized_speaker_shock
   3f705ce..e359fce  master     -> origin/master
 * [new branch]      revert-8571e8c2 -> origin/revert-8571e8c2
Updating d91345c..25207ca
Fast-forward
 device/sprd/sharkle/common/DeviceCommon.mk         |    5 +-
 .../sprd/sharkle/common/handheld_core_hardware.xml |    2 +-
 ..._sharkle_pubcp_customer_Feature_Phone_modem.dat |  Bin 18208640 -> 18209376 bytes
 .../sharkle/sp9820e_xtc/modem_bins/ltemodem.bin    |  Bin 18208640 -> 18209376 bytes
 ...sharkle_pubcp_customer_Feature_Phone_nvitem.bin |  Bin 811464 -> 811464 bytes
 .../sharkle/sp9820e_xtc/nv_project/audio_cvs.nvm   |   86 ++++-----
 .../nv_project/audio_sc8800g1_datacard_modem.nvm   |  200 ++++++++++----------
 ...sharkle_pubcp_customer_Feature_Phone_nvitem.bin |  Bin 811464 -> 811464 bytes
 .../java/android/net/MobileDataStateTracker.java   |    4 +-
 .../base/core/java/android/os/RecoverySystem.java  |    2 +-
 .../java/com/android/server/BatteryService.java    |    6 +-
 .../java/com/android/server/LightsService.java     |    8 +-
 .../android/server/NotificationManagerService.java |   21 +-
 .../server/power/DisplayPowerController.java       |    3 +-
 .../android/server/power/DisplayPowerState.java    |   15 +-
 .../android/server/power/PowerManagerService.java  |   18 +-
 .../jni/com_android_server_LightsService.cpp       |    6 +-
 .../internal/telephony/uicc/IccCardProxy.java      |   10 +
 kernel/drivers/power/bq25601_charger.c             |    4 +-
 kernel/drivers/power/sprd_27xx_fgu.c               |   34 ++--
 kernel/drivers/power/sprd_battery.c                |   16 +-
 kernel/drivers/power/sprd_charge_2721_helper.c     |    6 +-
 .../src/com/xtc/xtcdialer/XtcInCallPresenter.java  |    7 +-
 .../src/com/android/phone/CallLogger.java          |   11 +-
 trigger7niu.py                                     |   17 +-
 .../sprd/proprietories-source/autotest/light.cpp   |    4 +-
 vendor/xtc/apps/Debug/XTCSelftest.apk              |  Bin 4897493 -> 4871202 bytes
 vendor/xtc/apps/Release/XTCSelftest.apk            |  Bin 4720423 -> 4727494 bytes
 28 files changed, 262 insertions(+), 223 deletions(-)
 mode change 100644 => 100755 frameworks/base/core/java/android/net/MobileDataStateTracker.java
 mode change 100644 => 100755 frameworks/base/services/java/com/android/server/LightsService.java
 mode change 100644 => 100755 frameworks/base/services/java/com/android/server/power/DisplayPowerState.java
 mode change 100644 => 100755 frameworks/base/services/jni/com_android_server_LightsService.cpp
 mode change 100644 => 100755 frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/IccCardProxy.java
 mode change 100644 => 100755 vendor/sprd/proprietories-source/autotest/light.cpp

三、参考链接

  • 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

如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作

你可能感兴趣的:(#,Git学习)