Encryption keys management in GPG


When using GnuPG GPG for encryption/decryption of the documents we need to import the keys of the recipient. Look at the GPG as the complete encryption management toolkit that even keeps all the keys in its local cache/storage. Let’s take a look at how the keys management in GPG works.

How to list keys

  • List all keys
# gpg --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub   rsa4096 2020-08-03 [SC] [expires: 2020-08-04]
      8CB6409226EC77519EEAFFA89FAE55F9EC7E4783
uid           [ultimate] Ivan Dabic <[email protected]>
sub   rsa4096 2020-08-03 [E] [expires: 2020-08-04]
  • List public keys
# gpg --list-keys FULL
gpg: error reading key: No public key
[root@bluegrid-edu ~]# gpg --list-public-keys
/root/.gnupg/pubring.kbx
------------------------
pub   rsa4096 2020-08-03 [SC] [expires: 2020-08-04]
      8CB6409226EC77519EEAFFA89FAE55F9EC7E4783
uid           [ultimate] Ivan Dabic <[email protected]>
sub   rsa4096 2020-08-03 [E] [expires: 2020-08-04]
  • List secret keys
# gpg --list-secret-keys
/root/.gnupg/pubring.kbx
------------------------
sec   rsa4096 2020-08-03 [SC] [expires: 2020-08-04]
      8CB6409226EC77519EEAFFA89FAE55F9EC7E4783
uid           [ultimate] Ivan Dabic <[email protected]>
ssb   rsa4096 2020-08-03 [E] [expires: 2020-08-04]

Export Keys

  • First we locate the key we want to export by listing them out and finding the email describing the key:
# gpg --list-keys ivan dabic
pub   rsa4096 2020-08-03 [SC] [expires: 2020-08-04]
      8CB6409226EC77519EEAFFA89FAE55F9EC7E4783
uid           [ultimate] Ivan Dabic <[email protected]>
sub   rsa4096 2020-08-03 [E] [expires: 2020-08-04]
  • Then we export it:
# gpg --output ivan-dabic.gpg --export [email protected]

The exported key is now available to be shared with whomever you want to exchange encrypted messages. Note that this is a public key only, the secret one is still in the local store.

Importing Keys

When we share our public key the recipient needs to import the key:

# gpg --import ivan-dabic.gpg
Share this post

Share this link via

Or copy link