How to configure two SSH keys for two GitLab accounts and push / pull using TortoiseGit?

I am currently using GitLab as a remote GIT server.
I have no problem using the same Gitlab account with the SSH key assigned to it.

But now I have used a different Gitlab account and am trying to use the same SSH key for it, but I cannot add the key to this new account.
The error is as follows when I tried to add the key:

The key has already been taken
Fingerprint already taken

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

By the way, I am using a Windows system.

Thanks in advance !!

Updates

Below is my configuration file. And so it is:

#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 have two accounts on Gitlab,

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

However, I cannot access account_2 .

Previously, before I have this second GitLab account, I simply load the ssh key into account1 without having to install This . But now, following this, nevertheless, in the end, I was able to push to git@gitlab.com :{account_2}/repo1.git . And I use TortoiseGit to push / pull.

+5
source share
1 answer

Just declare all ssh private keys in the %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 

This assumes your ssh key set is:

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

Then you can use the urls for clone / push / pull:

 gitlabuser1:yourRepo1 gitlabuser2:yourRepo2 

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

You have a more detailed procedure in this blog post .

+17
source

All Articles