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?
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?
I would recommend a second key, for now without passphrase:
ssh-keygen -t rsa -C "your_email@example.com" -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 git@gitlab.com:<yourSecondACcount>/<yourRepo.git>
and will use your second key.
Generate a new key pair with:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
It will ask you to enter a name for the key file:
Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
Choose something different such as /Users/you/.ssh/gitlab_rsa
Then when you need it add this key to your ssh-agent with:
ssh-add ~/.ssh/gitlab_rsa
If you want a permanent access you can edit your ~/.ssh/config
file with:
Host gitlab_rsa
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile /home/<you>/.ssh/gitlab_rsa
Refer to this article for further details.
You need to create the file ~/.ssh/config
to define which key should use for every domain.
Create that file with nano and paste your configuration:
nano ~/.ssh/config
And add:
Host your-gitlab.com
HostName your-gitlab.com
IdentityFile ~/.ssh/your-gitlab-privkey
Generate SSH please follow below steps.
Open Git Bash on you machine
Enter the below command to genarate
ssh-keygen -t rsa -b 4096 -C "yourmail@example.com"
Generating public/private rsa key pair. Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):Press enter Enter passphrase (empty for no passphrase): Type a passphrase Enter same passphrase again: Type passphrase again
Once enter the confirm passphrase, will get confirmation message.
go to the gitpair.pub file location and right click open with notepad. copy the code and past the in the below text box, your email will pick automatically in the title box. then click add key.
Just apply two commands :
ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub
Copy ssh key and paste on browser