Ubuntu – Multiple SSH private keys for the same host

githubsshUbuntu

How can I store 2 different private SSH keys for the same host? I have tried 2 entries in /etc/ssh/ssh_config for the same host with the different keys, and I've also tried to put both keys in the same file and referencing it from one hosts setting, however both do not work.

More detail: I'm running Ubuntu server (12.04) and I want to connect to GitHub via SSH to download the latest source for my projects. There are multiple projects running on the same server and each project has a GitHub repo with it's own unique deloyment key-pair. So the host is always the same (github.com) but the keys need to be different depending on which repo I'm using.

Different /etc/ssh/ssh_config versions I have tried:

Host github.com
    IdentityFile /etc/ssh/my_project_1_github_deploy_key
    StrictHostKeyChecking no
Host github.com
    IdentityFile /etc/ssh/my_project_2_github_deploy_key
    StrictHostKeyChecking no

and this with both keys in the same file:

Host github.com
    IdentityFile /etc/ssh/my_project_github_deploy_keys
    StrictHostKeyChecking no

I've had no luck with either. Any help would be greatly appreciated!

Best Answer

I would do it like this:

Host project_1
    HostName github.com
    IdentityFile /etc/ssh/my_project_1_github_deploy_key

Host project_2
    HostName github.com
    IdentityFile /etc/ssh/my_project_2_github_deploy_key

and then use project_1 or project_2 as the host to access the repository.

Related Topic