如何为两个GitLab帐户设置两个SSH密钥并使用TortoiseGit进行推/拉操作? [英] How to set up two SSH keys for two GitLab accounts and push/pull by using TortoiseGit?

查看:465
本文介绍了如何为两个GitLab帐户设置两个SSH密钥并使用TortoiseGit进行推/拉操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用GitLab作为远程GIT服务器。

使用单个Gitlab帐户和分配给它的SSH密钥没有问题。



但现在我申请了另一个Gitlab帐户,并且正在尝试使用相同的SSH密钥,但我无法将密钥添加到此新帐户中。

当我尝试添加密钥时,错误如下:


密钥已被占用

指纹已被占用

那么我应该如何使用相同的密钥访问第二个Gitlab帐户?
如果不可能,我应该如何同时使用两个键。



顺便说一下,我使用的是windows系统。



预先致谢!

================== =================================================
更新:

以下是我的配置文件。如下所示:

  #my主帐户
主机{帐户1}
用户git
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile C:/ Users / {username} /。ssh / id_rsa1

#for NPR_HPTG帐户
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 无需设置。但现在通过以下步骤,最后我可以推送到 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 / clone / pull:

  gitlabuser1:yourRepo1 
gitlabuser2:yourRepo2

请确保您的 CMD 会话中包含%HOME%定义,通常为%USERPROFILE%(这是通过 git-cmd.bat



您有更详细的过程< 在此博客中。


Currently Im using GitLab as my remote GIT server.
I have no problem using single Gitlab account with SSH key assigned to it.

But now I applied another Gitlab account and I'm trying to use the same SSH key for it, but I cant add the key to this new account.
The error is as follows when I tried to add the key:

Key has already been taken
Fingerprint has already been taken

So how should I use the same key to access the second Gitlab account? if it is not possible, how should I use two keys at the same time.

By the way, I'm using windows system.

Thanks in advance!!

=================================================================== Updates:

Below is my config file. And it is as follows:

#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

And I'm having two Gitlab account,

git@gitlab.com:{account_1}/repo1.git
git@gitlab.com:{account_2}/repo1.git

Still, I cannot access to the account_2.

Previously, before I'm having this 2nd GitLab account, I simply upload the ssh key to the account1 without needing set This. But now by following this, still, in the end I could push to the git@gitlab.com:{account_2}/repo1.git. And I'm using TortoiseGit to push/pull.

解决方案

Simply declare each private ssh keys in a %HOME%/.ssh/config file:

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

That supposes your set of ssh keys are:

%HOME%/.ssh/id_rsa1 ; %HOME%/.ssh/id_rsa1.pub
%HOME%/.ssh/id_rsa2 ; %HOME%/.ssh/id_rsa2.pub

You can then use the urls for clone/push/pull:

gitlabuser1:yourRepo1
gitlabuser2:yourRepo2

Make sure your CMD session has %HOME% defined, usually to %USERPROFILE% (which is done for you with git-cmd.bat)

You have a more detailed procedure in this blog post.

这篇关于如何为两个GitLab帐户设置两个SSH密钥并使用TortoiseGit进行推/拉操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆