Git Tip – Use different SSH keys per server

A lot of public git repos are configured around the use of SSH keys for authentication. It’s a good idea to use different keys for each server.

Doing this requires two steps:

  • create a unique key for the server (and submit it as normal)
  • configure your SSH client to use the new key just for that server

Creating the key is easy (Linux/Mac – sorry, Windows users) – ssh-keygen -f ~/.ssh/site_key (rename site_key as appropriate)

Then, you need to add a section like this in your ~/.ssh/config file:

Host    site_name
IdentityFile ~/.ssh/site_key

(Again, change site to whatever is appropriate)

Congrats! You’ve now got a unique key just for one site – this means if they happen to get compromised, all you need to do is regenerate the key, and away you go.

(Of course, you may want to use passphrases, and other appropriate measures, on your end – but that’s good advice anyway)