Step by Step
First things first, make sure you have a GitHub account with 2FA enabled!
- 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)
- Go to https://github.com/settings/keys and add your public SSH keys there.
- Log on to each of your servers and create a crontab entry:
- 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...