如何在 Windows 10 Ubuntu 子系統上為 git 設定 SSH 金鑰

如何在 Windows 10 Ubuntu 子系統上為 git 設定 SSH 金鑰

我使用 Windows 10 上的 ubuntu bash(子系統)作為我的 shell。我有一個克隆的 gitlab git 儲存庫。當我從這個 shell 中使用 git 時,它與我的 Windows git 是分開的,我無法讓它使用我的 SSH 金鑰。它只是不斷詢問我的用戶/通行證。請注意,SSH 金鑰在 gitlab 中配置正確。

我將 id_rsa 和 id_rsa.pub 放在 ~/.ssh/ (ubuntu 子系統路徑)中

任何想法?

答案1

好的,我發現問題了。我使用https://url 作為來源而不是 ssh url ( [email protected]:...)。切換到 ssh url 後,使用 ssh 金鑰。

查看目前遙控器:git remote -v

切換遙控器:git remote set-url origin [email protected]:XXXXX

答案2

使用這個指令:

ssh-copy-id [email protected]

將使用者變更為您的使用者名,並將目標變更為您的目的地,以便它將您的 ssh 金鑰複製到目標系統。

相關內容