How to use different ssh keys with GitHub/Gitlab
1. Generate a new SSH key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
2. Start the ssh-agent in the background
eval "$(ssh-agent -s)"
3. Add your private key to the ssh-agent
ssh-add ~/.ssh/id_rsa
4. Create or modify the SSH config file
nano ~/.ssh/config
5. Add the following lines to the config file
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_gitlab
6. Save and exit the config file
7. Test the connection to GitHub
ssh -T [email protected]
8. Test the connection to GitLab
ssh -T [email protected]