How to setup two two different SSH-Keys for one GIT Host

A small HowTo Guid on how to use different SSH keys for different users on the same GIT Host like GitHub or Bitbucket.

Thomas Strohmeier
byte\schneiderei

--

As a development agency we are regularly working with different customers and different VCS platforms. Sometime it is required to create a dedicated account for a project with a new user. Simply adding a new SSH-Key leads to the problem of using the wrong SSH-key to the account. Here I want to provide you a simple solution for this problem:

1. Creating a SSH Config File

First we need a SSH config file. This is usually located at ~/.ssh/config.

#default account
Host github.org
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#account b account account
Host github.com-accb
HostName github.com
User git
IdentityFile ~/.ssh/account_b_id_rsa

2. Add SSH-Key of Account B

$ ssh-add ~/.ssh/account_b_id_rsa

3. Using the Alias Domain in git clone

If you now want to use the Account B in git clone simply replace the host with the alias:

$ git clone git@github.com-accb:companyB/repo.git

That’s it. ✅
PS: If you have an idea how to improve this setup, I would be happy If you leave a comment 😉

--

--

Entrepreneur | Student @ TU Graz | Software Engineer | DevOps | love learning & teaching | business software | privacy | https://byteschneiderei.com