因此,對于 Windows,我看到默認的 ssh 客戶端配置應該放置在,C:\Users\Admin\.ssh\config并且我使用相同的配置,而且我也是 Admin 用戶。
我添加了以下 ssh 客戶端配置:
PS C:\Users\Admin> type .\.ssh\config
Host gc
HostName gitlab.com
User git
IdentityFile ~/.ssh/company_gitlab
Host gp
HostName gitlab.com
User git
IdentityFile ~/.ssh/gitlab_personal
我從Powershell的測驗,它的作業對我的兩個公司和個人GitLab使用帳戶各自的SSH密鑰。
PS C:\Users\Admin> ssh -T git@gc
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
Welcome to GitLab, @johnwilson!
PS C:\Users\Admin> ssh -T git@gp
Enter passphrase for key 'C:\Users\Admin/.ssh/gitlab_personal':
Welcome to GitLab, @jwilson!
但是當涉及到 vscode 時,當我嘗試向遠程存盤庫推送或拉取更改時,公司和個人 GitLab 帳戶都會出現以下錯誤。
> git push -u gc master
[email protected]: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
> git push -u gp master
[email protected]: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
我想建議從這里也
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote add origin git@gc:company/infra_code/userlist.git
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote -v
origin git@gc:company/infra_code/userlist.git (fetch)
origin git@gc:company/infra_code/userlist.git (push)
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git ls-remote origin
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
611b36ef47056773c288499cb6974d8671196d78 HEAD
611b36ef47056773c288499cb6974d8671196d78 refs/heads/master
我很困惑,所以 vscode 沒有C:\Users\Admin\.ssh\config在 Windows 上選擇默認的 ssh 客戶端配置?。
或者我錯過了什么?
uj5u.com熱心網友回復:
檢查與名為“gc”的遠程關聯的遠程 URL
cd C:\path\to\gc\repo
git remote -v
如果 URL 以 開頭[email protected]:...,則不會使用該~/.ssh/config檔案及其gc條目。
使用正確的 URL 更改它
git remote set-url gc gc:<me>/<myrepo>
然后 VSCode 將選擇正確的條目,假設以 User 身份運行Admin。
該OP JohnW證實了討論:
我添加了一個沒有密碼的 SSH 密鑰,它適用于 vscode。所以這是 VSCode 無法通過密碼連接 ssh 密鑰的錯誤?
您需要確保首先激活 ssh-agent。
請參閱“在 Git for Windows 上自動啟動 ssh-agent ”
一旦 SSH 代理啟動(并且您的 SSH 私鑰密碼快取在其中),您就可以啟動 VSCode。它應該作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/389289.html
