關於 git 本地創建 SSH Key 遇到的一點問題(①file to save the key & ②the authenticity of host...)


背景

由於想測試一下 SSH Key 創建的路徑(.ssh 目錄路徑)對於不同位置 git 項目是否有效。

比如,.ssh 默認在 C:\[users]\[username] 目錄下,而項目 project 在 D:\ 目錄。測試結果是依然有效,即 .ssh 在 C:\[users]\[username] 目錄下時,在其他位置 push 時無需進行密碼認證(測試時項目以 SSH clone)。

PS:測試前已經將遠程倉庫托管平台公鑰配置好。

事件1(file to save the key)

在本地創建 SSH Key 過程中:

$ ssh-keygen -t rsa -C"email@xxx.xxx"

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/[usrname]/.ssh/id_rsa):

當在后面輸入其它路徑時發現不能鍵入.ssh,唯獨默認路徑中可包含 .ssh。不過只要路徑中不包括 .xxx 即可生成  SSH Key。

事件2(the authenticity of host...)

首次 clone(SSH)時報錯

 

The authenticity of host 'gitee.com (xxx.xxx.xxx.xxx)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
Bad packet length 2650498063.
ssh_dispatch_run_fatal: Connection to xxx.xxx.xxx.xxx port 22: message authentication code incorrect
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

事件2原因

當你第一次使用Git的clone或者push命令連接GitHub時,會得到一個警告:

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.

RSA key fingerprint is xx.xx.xx.xx.xx.

Are you sure you want to continue connecting (yes/no)?

 這是因為Git使用SSH連接,而SSH連接在第一次驗證GitHub服務器的Key時,需要你確認GitHub的Key的指紋信息是否真的來自GitHub的服務器,輸入yes回車即可。

Git會輸出一個警告,告訴你已經把GitHub的Key添加到本機的一個信任列表里了:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

這個警告只會出現一次,后面的操作就不會有任何警告了。

原因參考: 廖雪峰的官方網站-GIT-添加遠程倉庫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM