簡體   English   中英

無法“git pull”——主機密鑰驗證失敗

[英]Not able to "git pull" - Host key verification failed

我有對我們的生產服務器的 root 訪問權限,我想將 git 中的最新版本部署到服務器,但是當我在要更新的文件夾上“git pull”時遇到以下錯誤。

我瀏覽了一下,但找不到關於該做什么的明確答案。

登台服務器在同一台機器上運行,但只是在不同的文件夾中,當我pull該文件夾時一切正常。

我對 Linux 不是很有經驗,所以請幫我明確回答如何修復:-)

否則我可以訪問我需要的任何東西

ps 這在過去有效,所以我假設它與 SSH 密鑰有關

錯誤:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for www.site.org has changed,
and the key for the corresponding IP address x.x.x.x
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
*************
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:1
  remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R gitlab.site.org
ECDSA host key for gitlab.site.org has changed and you have requested strict checking.
Host key verification failed.

在日志中,您會看到以下文本:

(...)

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:1
remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R gitlab.site.org
ECDSA host key for gitlab.site.org has changed and you have requested strict checking.
Host key verification failed.

所以這是執行那里建議的命令的問題:

ssh-keygen -f "/root/.ssh/known_hosts" -R gitlab.site.org

視窗:

  1. 轉到/Users/Abhilash/.ssh/known_hosts並刪除其中的內容並保存。

Linux/Mac:

  1. 轉到~/.ssh/
  2. nano known_hosts
  3. 刪除里面的內容並保存ctrl+O

注意:再次按下時,系統會提示您保存密鑰。

按照這些對我有用的步驟后,我也遇到了同樣的問題。

對於 macOS:

Step 1: Go to Folder or use command+shift+g
Step 2: type "~/.ssh/"
Step 3: Open "known_hosts" file and Remove all the content
Step 4: Now Open terminal and pull from another branch, It will ask for password give your system password.

它肯定會起作用。

所有其他答案都會帶來安全風險。

出現此錯誤是因為您的known_hosts文件中有一條記錄,表明服務器應該具有特定的 ssh 密鑰。 但是當您嘗試連接時,服務器發送了一個不同的 ssh 密鑰,該密鑰與您的known_hosts文件中的密鑰不匹配。 您的特定錯誤消息說:

Offending ECDSA key in /root/.ssh/known_hosts:1

這意味着known_hosts文件中的第一行與遠程服務器發送的不同。

解決此問題的安全方法如下:

  1. 從可信賴的來源找出正確的密鑰指紋應該是什么。 例如,在這里您可以找到GitHubGitLab的正確指紋。 (如果您的組織自托管 GitLab,您將需要與您的管理員聯系以獲取 ssh 密鑰指紋。)
  2. 檢查known_hosts文件中的現有指紋是否正確。
    您可以運行ssh-keygen -lf ~/.ssh/known_hosts (或/root/.ssh/known_hosts在您的情況下)從您的known_hosts文件生成 SHA256 指紋。 您的錯誤消息說問題出在第一個鍵上。 在 GitHub 或 GitLab 上找到等效的 SHA256 指紋並檢查它是否完全匹配。
    例如,這是上述命令的輸出:
     256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw gitlab.com (ECDSA)
    這是來自GitLab網站的 ECDSA SHA256 指紋:
     HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw
  3. 如果來自known_hosts的現有指紋與來自GitHubGitLab網站的官方指紋匹配,則ssh已檢測到中間人 (MitM) 攻擊。 停止 不要連接到服務器。 嘗試從不同的 Internet 連接進行連接。 與您的管理員交談。
  4. 如果known_hosts的現有指紋官方指紋不匹配,那么要么您之前受到了中間人攻擊,要么托管 GitLab 的服務器已更改其 ssh 密鑰。 您可以從known_hosts文件中刪除指紋。 注意:只刪除導致問題的特定指紋。)下次連接到 GitLab 時,系統會提示您將新指紋添加到known_hosts文件中。
     The authenticity of host 'gitlab.com (172.65.251.78)' can't be established. ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw. Are you sure you want to continue connecting (yes/no/[fingerprint])?
    仔細檢查指紋是否與GitHubGitLab網站顯示的內容匹配,然后相應地輸入yesno

嘗試將 ssh 替換為:

ssh -oStrictHostKeyChecking=no

因為如果密鑰尚未被接受,那么它會詢問您是否要接受它是/否。 或者,您也可以在 SSH 命令之前在 CI 文件中執行此操作:

echo "StrictHostKeyChecking no" >> ~/.ssh/config

禮貌: https://forum.gitlab.com/t/error-host-key-verification-failed/77315/3

如果您想永久刪除此消息,您可以編輯您的 ssh 配置文件 ( ~/.ssh/config ) 以包括:

Host {YOUR HOST HERE}
 StrictHostKeyChecking no
 UserKnownHostsFile /dev/null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM