Ubuntu – How to share the public OpenPGP key using GnuPG

gnupg

I used GnuPG to generate a key. But looking at the GUI, I cannot tell where my public key is stored. I would like to share it with friends.

I clicked on export, this exported a name.asc file, but when I open the file in gedit it is labeled as a private key so I am assuming this is not the public key for sharing.

Best Answer

From the command line:

Run gpg --list-keys 'your name' to list the keys you currently have (replacing your name with the name you have while setting up):

$ gpg --list-keys muru      
/home/muru/.gnupg/pubring.gpg
--------------------------------
pub   2048R/AD0CC9B4 2015-07-15
uid                  muru
sub   2048R/450DAD90 2015-07-15

Note the fingerprint of the key you want to export. The fingerprint of my public key is AD0CC9B4. To export it, I'll do gpg --export (-a is for ASCII armour, so that the key is in the usual base64-encoded form):

$ gpg -a --export AD0CC9B4
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFWm4zkBCADYo5ffanvwBVGMbfp3g+/RMYb41QRZXCGSUhZkU7m3BpPSoO/4
NBzD4KKAU6CTVzBmVmZoFGgK2dDIOv+ZCkB4USZM2cvvpu7I+jfaYZW7ouQ4uEYu
8xY8ugFn5ImsK4KN0OP+Iw1VBXLdvj/rEiV+gcH8QV0XhsfgczCxjS1dMV3AMD+h
# snip
Wo0X3XmrPpaHJf7MsjGmJGbHNX9ZLllyFWQPlNdu9ilLI9GMjSpJSqQ=
=l/Xm
-----END PGP PUBLIC KEY BLOCK-----

You can redirect the output to a file:

gpg -a --export AD0CC9B4 > my-pubkey.asc

Then my-pubkey.asc should contain your ASCII-armoured public key.

The corresponding private key can be exported with:

gpg -a --export-secret-keys AD0CC9B4

The output of this command will begin with

-----BEGIN PGP PRIVATE KEY BLOCK-----