List

We will start by assuming you have multiple GitHub accounts configured with different SSH keys which are stored on your local PC. If you are on Windows I recommend using Git BASH. This tool can be accessed from this website.

Each Github account is associated with a public/private key pair which are usually stored under .ssh folder in your home directory. Note that this folder is hidden in Linux-bases operating systems. All the configuration files referred to in this tutorial should reside in this directory.

In the simplest case you will have 2 different accounts on two different Github domains, one in the github.com and one in github.yourcompany.be. Let’s say the the associated private keys with these accounts are id_rsa_githubcom and id_rsa_yourcompany, respectively.

In order to configure access through both of the keys we need to have a configuration file named config within the .ssh directory. For our particular case being demonstrated this file reads


Host yourcompany
HostName github.yourcompany.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_yourcompany

Host githubcom
User git
Hostname github.com
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/id_rsa_githubcom

Now we need to make a distinction depending on which host the repository we are trying to access resides on. The following command will clone the given repository from github.yourcompany.com using the correct SSH key for access.
git clone yourcompany:company_user/company_repository.git
Similarly if you wanted to access another repository from github.com you will use the following command to use the correct SSH key this time as well.
git clone githubcom:githubcom_user/githubcom_repository.git

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.