Manage multiple ssh accounts for GitHub and GitLab
1. Generate new RSA SSH keys
ssh-keygen -t rsa -b 2048 -C "email@example.com" |
for example, I have 2 keys in my laptop
~/.ssh/id_rsa |
Next, add the new key you just created
ssh-add ~/.ssh/tpp_rsa |
You can check your added keys
ssh-add -l |
2. Modify the ssh config
nano ~/.ssh/config |
Gitlab Personal |
3. Test the connection
ssh -T git@gitlab.com |
4. Add public key to your source control profile setting
Copy the public key to clipboard
cat ~/.ssh/tpp_rsa.pub | xclip -selection c |
Paste the key to gitlab ssh setting
Paste the key to github ssh setting
5. Clone the source code using different user
Use this config for your personal account git clone git@gitlab.com:myname/myproject.git
For other account git clone git@gitlab.com-tpp:orga/projecta.git
That's all! Good luck!