Using GitHub to manage multiple SSH keys across various devices

A little tip to take away some of the manual pain with having to add or update SSH keys across your servers.

Using GitHub to manage multiple SSH keys across various devices

Step by Step

First things first, make sure you have a GitHub account with 2FA enabled!

  1. Go through your devices and find the public SSH keys (e.g. ~/.ssh/id_rsa in Linux, or C:\Users\USERNAME\.ssh\id_rsa.pub in Windows)
  2. Go to https://github.com/settings/keys and add your public SSH keys there.
  3. Log on to each of your servers and create a crontab entry: crontab -e
  4. Paste the following: */8 * * * * /usr/bin/wget https://github.com/USERNAME.keys -O ~/.ssh/authorized_keys (replacing USERNAME with your own GitHub username and update the timings if you wish)

That's it! The cronjob will pull the GitHub keys at the specified time and apply them to your server's list of authorized_keys.

You could always improve this by adding in validations to check if anything has changed between Github and your server, or checking that your server has internet access first before trying to download a file, etc...