目前我使用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
推/拉。
答案 0 :(得分:17)
只需在%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
然后您可以使用网址进行克隆/推/拉:
gitlabuser1:yourRepo1
gitlabuser2:yourRepo2
确保您的CMD
会话已定义%HOME%
,通常为%USERPROFILE%
(通过git-cmd.bat
为您完成)
您有一个更详细的程序in this blog post。