如何为两个GitLab帐户设置两个SSH密钥,并使用TortoiseGit进行推/拉?

问题描述 投票:5回答:1

当前,我正在使用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帐户,

[email protected]:{account_1}/repo1.git
[email protected]:{account_2}/repo1.git

仍然,我无法使用account_2

[以前,在拥有第二个GitLab帐户之前,我只需要将ssh密钥上传到account1,而不需要设置This。但是,现在仍然可以通过遵循此步骤来推动[email protected]:{account_2}/repo1.git。我正在使用TortoiseGit推/拉。

git ssh key gitlab tortoisegit
1个回答
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为您完成)

您有一个更详细的过程git-cmd.bat

© www.soinside.com 2019 - 2024. All rights reserved.