Jens Willmer

Tutorials, projects, dissertations and more..

GitHub with multiple SSH deployment keys

This post explains how to use multiple deployment keys with Git and is my summary of a blog post by ramachandra1. The post builds upon the previous post about GitHub SSH based authentication.

Modify your SSH config to reference multiple host aliases: nano ~/.ssh/config

Host ProjectAliasOne 
    User git
    IdentityFile ~/.ssh/github/project-one/id_rsa
Host ProjectAliasTwo
    User git
    IdentityFile ~/.ssh/github/project-two/id_rsa

Register the SSH aliases in the SSH agent via:

eval `ssh-agent`
ssh-add ~/.ssh/github/project-one/id_rsa
ssh-add ~/.ssh/github/project-two/id_rsa

Change the access rights of the SSH key files to prevent a constant password prompt from GitHub:

chmod -R 600 ~/.ssh/github/project-one
chmod -R 600 ~/.ssh/github/project-two

Test that it is working:

ssh -T git@ProjectAliasOne
ssh -T git@ProjectAliasTwo

Now you can use the following syntax to pull a GitHub repository:

git clone git@ProjectAliasOne:repo-owner-name/repo-name.git