![](/img/trans.png)
[英]How do I push to two different GitHub accounts using SSH keys in Powershell?
[英]How to set up two SSH keys for two GitLab accounts and push/pull by using TortoiseGit?
目前我使用GitLab作為我的遠程GIT服務器。
使用分配了SSH密鑰的單個Gitlab帳戶我沒有問題。
但現在我應用了另一個Gitlab帳戶,我正在嘗試使用相同的SSH密鑰,但我無法將密鑰添加到這個新帳戶。
當我嘗試添加密鑰時,錯誤如下:
關鍵已經采取
指紋已經被采用
那么我應該如何使用相同的密鑰訪問第二個Gitlab帳戶呢? 如果不可能,我應該如何同時使用兩個鍵。
順便說一句,我正在使用Windows系統。
提前致謝!!
================================================== =================更新:
下面是我的配置文件。 它如下:
#my primary account
Host {account1}
User git
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile C:/Users/{username}/.ssh/id_rsa1
#for NPR_HPTG account
Host {account2}
User git
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile C:/Users/{username}/.ssh/id_rsa2
我有兩個Gitlab帳戶,
git@gitlab.com:{account_1}/repo1.git
git@gitlab.com:{account_2}/repo1.git
不過,我無法訪問account_2
。
以前,在我擁有第二個GitLab帳戶之前,我只需將ssh
密鑰上傳到account1
而無需設置This 。 但是現在通過這樣做,最后我仍然可以推送到git@gitlab.com:{account_2}/repo1.git
。 我正在使用TortoiseGit
來推/拉。
只需在%HOME%/.ssh/config
文件中聲明每個私有ssh密鑰:
Host gitlabuser1
User git
Hostname {hostname}
PreferredAuthentications publickey
IdentityFile C:/Users/{username}/.ssh/id_rsa1
Host gitlabuser2
User git
Hostname {hostname}
PreferredAuthentications publickey
IdentityFile C:/Users/{username}/.ssh/id_rsa2
假設您的ssh密鑰集是:
%HOME%/.ssh/id_rsa1 ; %HOME%/.ssh/id_rsa1.pub
%HOME%/.ssh/id_rsa2 ; %HOME%/.ssh/id_rsa2.pub
然后,您可以使用克隆/推/拉的URL:
gitlabuser1:yourRepo1
gitlabuser2:yourRepo2
確保您的CMD
會話已定義%HOME%
,通常為%USERPROFILE%
(使用git-cmd.bat
為您完成)
您在此博客文章中有更詳細的過程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.