Friedrich Ewald My Personal Website

Managing mulitple SSH identities for Git

There are multiple steps required to be able to push/pull from Git repositories with different identities when using SSH Keys.

  1. Set up different host names in ~/.ssh/config, similar to this example:
Host github-identity1.com
	HostName github.com
	User git
	IdentityFile ~/.ssh/identity1

Host github-identity2.com
	HostName github.com
	User git
	IdentityFile ~/.ssh/identity2
When cloning the repository make sure to use the correct host name, correspdonding to the identity, for example git clone github-identity1.com:user/repo.git. This might sometimes not be enough when pushing to a remote repository. The reason for this is that multiple identities are added to the ssh-agent. To obtain the list of added identities, execute ssh-add -l which returns a list of identities. Those identities will be tried out in order when attempting to push to a remote repository. If the first one fails, the second one will not be tried, instead the whole push fails. To fix this, I had to delete all identities via ssh-add -D and then re-add them one by one via ssh-add path/to/private_key.


About the author

is an experienced Software Engineer with a Master's degree in Computer Science. He started this website in late 2015, mostly as a digital business card. He is interested in Go, Python, Ruby, SQL- and NoSQL-databases, machine learning and AI and is experienced in building scalable, distributed systems and micro-services at multiple larger and smaller companies.