I have two Gitlab accounts. On my old account I added an ssh-key that is located in ~/.ssh/id_rsa.pub
on my computer.
Now I want to add another ssh-key for my new Gitlab account. How do I do this without having the ssh-keys conflict?
Open a terminal and use the ssh-keygen command with the -C flag to create a new SSH key pair. Replace the following: KEY_FILENAME : the name for your SSH key file. For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh-key.
Gitlab won't allow reuse of a public ssh key for multiple accounts. To get around this you need to create a second ssh key for the second account.
I would recommend a second key, for now without passphrase:
ssh-keygen -t rsa -C "[email protected]" -P "" -q -f ~/.ssh/gitlab_rsa
That will create (without any prompt) ~/.ssh/gitlab_rsa
(private key) and ~/.ssh/gitlab_rsa.pub
(public key)
You need to register that second gitlab_rsa.pub
public key to your second GitLab account.
Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'.
Then add a ~/.ssh/config
file with:
Host gitlab_rsa
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile /home/<you>/.ssh/gitlab_rsa
Finally, you can clone any GitLab repo as your second identity with:
git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>
That will be replaced automatically with [email protected]:<yourSecondACcount>/<yourRepo.git>
and will use your second key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With