Skip to content

Instantly share code, notes, and snippets.

@cdelorme
cdelorme / instructions
Last active May 3, 2023 12:30
Automatically Update Remote Authorized Keys
I tend to break and rebuild my systems regularly. It has gotten to the point that I generally do not have an SSH key for over a year.
This has created a serious dilemma when it comes to maintaining access to remote systems. I usually disable normal password access on any servers I maintain, which means unless I have multiple systems that can access so I can replace the keys I could permanently loose access to those systems. In considering possible solutions I came up with one that has saved my bacon regularly.
First, I use my [dot-files](https://github.com/cdelorme/dot-files) repository after installing any new system. If that system is secure I will generate a new SSH key and load it into github via curl through their api.
On servers which I need to retain access, I create a simple bash script to poll my github accounts keys. I throw it into a user-local `~/.bin/update-keys` file, and make it executable.
Finally, I modify the crontab to execute this script regularly: