如何使用 TortoiseGit 为两个 GitLab 帐户和 push/pull 设置两个 SSH 密钥?
How to set up two SSH keys for two GitLab accounts and push/pull by using TortoiseGit?
目前我正在使用 GitLab 作为我的远程 GIT 服务器。
我可以使用分配给它的 SSH 密钥的单个 Gitlab 帐户。
但现在我申请了另一个 Gitlab 帐户,我试图为它使用相同的 SSH 密钥,但我无法将密钥添加到这个新帐户。
我尝试添加key时报错如下:
Key has already been taken
Fingerprint has already been taken
那么应该如何使用同一个密钥访问第二个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
到 push/pull。
只需在 %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
然后您可以使用 clone/push/pull:
的网址
gitlabuser1:yourRepo1
gitlabuser2:yourRepo2
确保您的 CMD
会话已定义 %HOME%
,通常为 %USERPROFILE%
(使用 git-cmd.bat
为您完成)
你有更详细的程序in this blog post。
目前我正在使用 GitLab 作为我的远程 GIT 服务器。
我可以使用分配给它的 SSH 密钥的单个 Gitlab 帐户。
但现在我申请了另一个 Gitlab 帐户,我试图为它使用相同的 SSH 密钥,但我无法将密钥添加到这个新帐户。
我尝试添加key时报错如下:
Key has already been taken
Fingerprint has already been taken
那么应该如何使用同一个密钥访问第二个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
到 push/pull。
只需在 %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
然后您可以使用 clone/push/pull:
的网址gitlabuser1:yourRepo1
gitlabuser2:yourRepo2
确保您的 CMD
会话已定义 %HOME%
,通常为 %USERPROFILE%
(使用 git-cmd.bat
为您完成)
你有更详细的程序in this blog post。