Server specific SSH keys

Because this has confounded me on multiple occasions and I keep on forgetting to record the solution.

Whenever I create or add an SSH key to my ~/.ssh/ folder I name it something more memorable e.g. id_github or id_bitbucket (it’s wise to have separate keys for separate public repos like these – means you can revoke access on a per-key basis) – this will sometimes confuse Git, as it won’t be able to find the id_rsa file it’s used to. As such you need to edit the ~/.ssh/config file and add in the servers you’d like to connect to and with which key.

I added something like the following. Add a separate block per server.

Host server.com
    HostName server.com
    User UserName
    IdentityFile ~/.ssh/server_private_key

Leave a comment