The day when I (almost) lost my keys
Testing backups is important, and I learned the hard way.
2025-09-02 - 2 min read
hugo@superuser:/var/log/ $ less when-i-lost-my-keys.md
2025-09-02 - 2 min read
Once upon a time, I screwed up my GPG keys. Here’s how everything happened.
There are a lot of ways to manage GPG keys, from a simple generate-and-use setup on a single machine to a more complex setup like mine.
As we say in Portugal, every monkey to its branch. I have four key pairs in total. The Certify key stays on an offline machine while the others are stored on my NitroKey (NK) for everyday use.
I need to renew the keys every six months, and the procedure is fairly simple:
This seems like a good plan right? So I thought, and I even tested the backup on the last step, but the way I did it was totally wrong since I hadn’t verified that I could to use the private keys.
Last time I renewed the keys, everything went according to plan and I was happy – until I needed to SSH into a machine. The first thing that occurred to me was that I missed something in step 3, so back to the offline machine and hello? Where are my private keys? I panicked for one minute and then I told myself, “That’s OK, I’ll just log into every machine using the backup key and replace it with the new one”. And then I really panicked a lot. Want to guess what encrypted the backup SSH key?
Yeah, at that moment I lost everything. including passwords and backups.
OK I thought, let’s roll back every single backup I have of the keys, I just needed one with the encryption private key. Out of all the backups, the first one had all the private keys. I quickly copied it onto the NK and voilá, I had access to my passwords and my backups.
After that horror story, I revoked the now privateless keys and created newer ones and pubished them to keys.openpgp.org.
And now, before I copy the keys into the NK, I restore the backup and check that all private keys are there, just to make sure that the backup is fully working.
Remember, kids: an untested backup isn’t a backup!