Today I learned how to use multiple SSH keys one a computer.
At work, all projects are hosted on our company’s internal git server running GitLab CE. while I put all my personal projects on GitHub.
I wanted to use different keys for GitLab and GitHub. So that I can have different passphrases for each SSH key, making it a bit more secure.
I use RSA key for both services for now.
Generating SSH Keys
I generated 2 SSH key pairs. The default one is for company’s work at GitLab.
$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
and another pair for GitHub stored at
$ ssh-key -t rsa -b 4096 -C "firstname.lastname@example.org" -f ~/.ssh/github
~/.ssh/ folder, I have 2 pairs of SSH keys.
$ ls -1 ~/.ssh id_rsa id_rsa.pub github github.pub
Update SSH Config File
Now I have to tell SSH client to use the different private key for GitHub.
~/.ssh/config file, add a new configuration for GitHub.com:
host github.com identityfile ~/.ssh/github
This means every time it has to make a connection to
use another private key at
~/.ssh/github instead of the default one.
This includes git as well.
I added the public key
~/.ssh/github.pub to my GitHub account settings page.
and make a test connection to verify that it works.
$ ssh -T email@example.com Hi armno! You've successfully authenticated, but GitHub does not provide shell access.