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
~/.ssh/tpp_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
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa

# Gitlab Working
Host gitlab.com-tpp
HostName gitlab.com
User git
IdentityFile ~/.ssh/tpp_rsa

# GitHub Personal
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

# GitHub Working
Host github.com
HostName github.com-tpp
User git
IdentityFile ~/.ssh/tpp_rsa

3. Test the connection

ssh -T git@gitlab.com
ssh -T git@gitlab.com-tpp
ssh -T git@github.com
ssh -T git@github.com-tpp

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!