I know this might sound counter-intuitive, but is it possible to configure gpg to store public keys in encrypted state on disks? Such that when encrypting a message to someone, user would be asked to first enter a passphrase to decrypt recipient's public key.

As we move towards a "post-quantum" age, one might as well encrypt public keys for storage for a special case of "not-too-public" public key cryptography.

1 Answer 1


There's no built-in support for that, mostly because there's not really any point. Public keys are assumed to be public, meaning anybody who wants them can have them. Even if they were stored in encrypted form on your computer, they would typically be stored in plain text in many other places, such as keyservers, email messages, the computers of other people you communicate with, your github account, and so on.

Besides, what's your threat model here? If you're worried that malicious software on your computer will read the public keys and then crack them with quantum computing hardware, the solution is not "store the keys in encrypted form", it's "don't run malicious software on your computer"! By the time that happens, it's game over. The malware could monitor your keystrokes to decrypt the public key, but they could also just capture your private key when you next use it, and that's far, far worse. If your concern is that your computer will be lost/stolen and the attacker will use quantum computers to break all the public keys in your keychain (which would let them decrypt messages you've sent, decrypt messages sent to you, and forge your digital signature), the obvious solution there is to encrypt your entire drive (including all those messages and the entire keychain), using something like Bitlocker, File Vault, or LUKS. That's obviously still not complete protection because, as mentioned above, your public key is probably all over the place already... but it's more convenient and does a better job of protecting your overall security than what you actually asked for.

With that said, if you really want to, you can encrypt your GPG public keyring. The command will be something like gpg --symmetric ~/.gnupg/pubring.kbx. Don't forget to delete the plain-text pubring file afterward. Then you can decrypt it by using gpg -d ~/.gnupg/pubring.kbx.gpg (make sure the resulting file is in the right location for gpg to find) and use that until you no longer want it, at which point you can delete it again. You could also do something like make your pubring (or whole .gnupg folder) a symlink to an encrypted volume, either on removable storage or something like a Veracrypt encrypted volume.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .