I use one computer for both my personal and business projects. This means I have multiple github accounts that I use on the computer. The problem with that is that I need multiple SSH keys each connecting to a different github account.
I needed a nice solution on how to use multiple ssh keys for github.
First create your 2 ssh keys
~/.ssh/id_rsa_personal
~/.ssh/id_rsa_work
Add both the keys
$ ssh-add ~/.ssh/id_rsa_personal
$ ssh-add ~/.ssh/id_rsa_work
Git allows you to customise this by using the git config file. In your ~/.ssh folder create a new file called config
.
Inside this file you can paste the config on what key to use for a certain account.
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personalHost github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
When you clone your repo ensure that you set the username for that repo by changing the local config.
$ git config user.name "personal"
$ git config user.email "personal@gmail.com"
$ git config user.name "work"
$ git config user.email "personal@gmail.com"
Originally published at https://paulund.co.uk.