1. 程式人生 > 其它 >問題解決 - The RSA host key for gitlab has changed

問題解決 - The RSA host key for gitlab has changed

問題

git pull 遇到如下問題

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for gitlab.xxx.com has changed,
and the key for the corresponding IP address 11.11.111.111
has a different value. 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.
Offending key for IP in /c/Users/xxx/.ssh/known_hosts:2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:8vm2iWaWLwxxxxxxxxxxxxxxxxxxxxxxxxxxYJF6jvpo.
Please contact your system administrator.
Add correct host key in /c/Users/xxx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /c/Users/xxx/.ssh/known_hosts:3
RSA host key for gitlab.xxx.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.

原因

本地計算機 known_hosts 中記錄的 git 伺服器的公鑰和實際返回的公鑰不匹配。

解決

1

最快的方法:更新一下 C:\Users\xxx\.ssh\known_hosts 中的記錄

  • 開啟 known_hosts 檔案,找到 gitlab.xxx.com 對應的記錄,刪掉
  • 然後執行 git pull ,會提示你要不要將新的伺服器地址加到 known_hosts 中,如果不像每次都提示一遍的話就加一下

2

當然,最保險的話,是重新生成一遍 ssh key pair,然後把伺服器上的公鑰也更新下

參考 -> https://www.jianshu.com/p/04a05cf6ff9f