Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raineorshine/ad200b2bbe09bd01dc900aa5a2e6b39b to your computer and use it in GitHub Desktop.
Save raineorshine/ad200b2bbe09bd01dc900aa5a2e6b39b to your computer and use it in GitHub Desktop.
Instructions for exporting/importing (backup/restore) GPG keys

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/
# or, instead of backing up trustdb...
gpg --export-ownertrust > raine-ownertrust-gpg.txt

NOTE The GPG manual suggests exporting the ownertrust instead of backing up the trustdb, although it doesn't explain why.

Restore the public and secret keyrings and trust database

cp /path/to/backups/*.gpg ~/.gnupg/
# or, if you exported the ownertrust
gpg --import-ownertrust raine-ownertrust-gpg.txt

Below is mainly about trusting my key once I've imported it (by either restoring the pubring.gpg and secring.gpg, or by using --import). This seems to be what I do the most as I either forget to import the trustdb or ownertrust.

gpg --edit-key raineorshine@gmail.com
gpg> trust
Your decision? 5 (Ultimate trust)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment