backing up and syncing gpg keys

table of contents

public keyring, and "non-exportable" stuff

this includes local signatures

to a file

gpg --export --export-options export-backup >file
...
gpg --import --import-options import-restore >file

directly over ssh

gpg --export --export-options export-backup | ssh user@host -- gpg --import --import-options import-restore

trust values

to a file

gpg --export-ownertrust >file
...
gpg --import-ownertrust >file

directly over ssh

gpg --export-ownertrust | ssh user@host -- gpg --import-ownertrust

secret keys

note that since importing a password-protected secret key asks for the password, it is difficult to do while piping over ssh.

gpg --export-secret-keys >file
...
gpg --import file

just the subkeys

you can instead share only the secret subkeys with a less-trustworthy computer (such as a laptop you take with you) so that you can revoke them and create new subkeys, without the hassle of your entire key needing to be revoked.

gpg --export-secret-subkeys >file
...
gpg --import file