
我正在使用 Terraform 設定 EC2 實例,在此過程中我需要執行一個大型腳本。我想從我們的 gitlab 儲存庫下載腳本,如下所示:
git clone [email protected]:a_name/project.git
Cloning into 'project'...
The authenticity of host 'gitlab.something.org (12.34.56.78)' can't be established.
ECDSA key fingerprint is SHA256:....
Are you sure you want to continue connecting (yes/no)? yes
Cloning into ...
當我從命令列運行此命令時,我必須確認,但這在我的情況下是不可能的。
但是,/var/log/cloud-init-output.log
我看到了這一點(上傳正確的私鑰後):
Cloning into 'project'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我希望這個錯誤只是沒有回答“是”的結果 - 有沒有辦法告訴 git 沒關係,我知道我在做什麼,然後繼續吧?
答案1
使用您的自動化系統部署known_hosts
具有正確主機金鑰的檔案。您可以從您自己的known_hosts複製條目,例如使用ssh-keygen -F gitlab.something.org
(即使文件已被散列,這也有效)。
該檔案可以部署在~/.ssh/known_hosts
或 at /etc/ssh/ssh_known_hosts
。
注意主機金鑰驗證不是只是為了讓你確認你在做什麼;它的作用是確認你正在嘗試做的事情與實際發生的事情相符。與 HTTPS 非常相似,它旨在防範 MITM 攻擊等外部因素 - 您輸入的 URL 可能始終 100% 正確,但封包可能會在幾個月或幾年後突然重新路由到錯誤的伺服器。