How to use different SSH keys for different Github accounts

Github image

1. Context

As self-employed developer I have two github accounts:

So I would like to use a different ssh key to authenticate with per account.

The default ssh key is coupled to robbypelssers and I created a second ssh key for pelssersconsultancy.

1
2
3
robbypelssers1@Macbook-Robby-Pelssers:~/.ssh$ ls -la *pelssersconsultancy*
-rw------- 1 robbypelssers1 staff 3243 Apr 23 11:39 id_pelssersconsultancy_rsa
-rw-r--r-- 1 robbypelssers1 staff 757 Apr 23 11:39 id_pelssersconsultancy_rsa.pub

In order to always couple the my private .ssh key ‘id_pelssersconsultancy_rsa’ to
any repository from pelssersconsultancy I added the following entry to .ssh/config

1
2
3
4
5
robbypelssers1@Macbook-Robby-Pelssers:~/.ssh$ more config
Host github.com-pelssersconsultancy
HostName github.com
User git
IdentityFile ~/.ssh/id_pelssersconsultancy_rsa

So in order to checkout the project mytodolist normally I would do

1
$ git clone git@github.com:pelssersconsultancy/mytodolist.git

but instead now I can do

1
$ git clone git@github.com-pelssersconsultancy:pelssersconsultancy/mytodolist.git

Just to verify:

1
2
3
4
$ git remote show origin
remote origin
Fetch URL: git@github.com-pelssersconsultancy:pelssersconsultancy/mytodolist.git
Push URL: git@github.com-pelssersconsultancy:pelssersconsultancy/mytodolist.git
Share Comments