Managing OpenPGP Keys

This instruction will guide you step-by-step through creating OpenPGP public/private key pairs, exporting public keys to key servers, and finding OpenPGP public keys for secure communication with others.

First step before start

First read the instructions in OpenPGP Best Practices carefully to ensure your system generates a strong key and receives key updates from a well-maintained keyserver. This will require to make changes to the gpg.conf configuration file, which is located in different places depending on your operating system. In Linux it is located in ~/.gnupg/gpg.conf.

Linux

Using GNOME’s GUI frontend: Seahorse

What is Seahorse?

Seahorse is a GUI tool for creating and managing OpenPGP keys, securely storing passwords, and creating and managing SSH certificates. It uses GPG as the back-end OpenPGP implementation.

Create and export an OpenPGP Public/Private Key pair

  1. Launch Seahorse. It should be installed by default.
  2. Select GnuPG keys.
  3. Select the + sign to create a new key.
  4. Select PGP Key.
  5. Enter your email and the name you would like to be associated with the key. This doesn’t need to be your real name.
  6. Select advanced options.
  7. Encryption type should be RSA.
  8. Key strength should be 4096.
  9. Expiration date should be within less then two years. You can always extend the key expiration as long as you still have access to the key, even after it has expired. Why should I set an expiration -.
  10. Enter a strong password that you can remember. If you forget this password, it cannot be recovered and any encrypted data you have using it for, including emails, will be permanently inaccessible.
  11. The computer will now generate the key, which may take some time. After this, you will have an OpenPGP key pair that is ready to be used—Great! You can manage the key options, export the public key, change the password, delete and/or revoke the key, and perform other key adjustments through the Seahorse user interface or the command line.
  12. Optional: At this point, you can publish your public key to a key server where people can request it remotely to be able to send encrypted data and emails to you. Before you continue, please make sure you have selected a good keyserver. Once you are ready:
    1. Select the Key(s) you want to publish. Hold Ctrl and click to select more than one, or press Ctrl+A to select all keys.
    2. Navigate to RemoteSync and Publish Keys…
    3. Press the Key Servers button.
    4. Publish the keys to any keyserver (select one if the “Sync” button was grayed out in the previous screen); they all synchronize with each other, so your key will be on each one.
    5. Recommended: Check the Automatically retrieve keys from key servers but do not check the Automatically synchronize modified keys with key servers check boxes. Instead, please consider using parcimonie.
    6. Press the Close button and then the Sync button to synchronize your keys.

Your public key is now published on the key servers and is accessible to others!

Find or import someone else’s OpenPGP Public Key

If you want to communicate with others securely or encrypt data that only they can read, you first need to import their public key into your keyring. Note: The John Q. Alias key is used as an example key for generating a key above and also for importing a key below; in the case of importing, it is used to refer to the person for whom you’re searching, not yourself.

Import from a key file

If someone exports their key to a file and sends it to you, you can import it into your keyring via Seahorse by:

  1. Navigating to FileImport…
  2. Locate where you saved the key file, selecti it, and pressi the Open button.

The key that was stored in the key file has now been imported into your keyring!

Searching on keyservers

  1. Navigate to RemoteFind Remote Keys… in Seahorse
  2. Type some key words (a name or alias) to search the key servers. The best way to find someone is to search for their email address, as it’s uniquely tied to them.
  3. Select and review the keys that are returned to determine whether the key(s) returned belong to the person you’re looking for. You can review additional information about the key by pressing the Properties button.
  4. Once you’ve determined and selected the key(s) you want to import into your local keyring, press Import.

Their public key has now been imported into your keyring!

Verifying a key

Anyone can publish a key on a keyserver. For example, for a fun trick, try searching for Edwards Snowden’s key. There are many, many keys! Before you start using a key, you should verify the key’s fingerprint with the individual with whom you wish to communicate. You should not do this by email! The best practice is to verify the fingerprint in person. At a minimum, you should use voice/video to confirm that you have the right key. To verify the fingerprint, you can use the following steps:

  1. Open seahorse
  2. On the view menu, select show any
  3. Locate the key that you have already imported
  4. Select properties (right click)
  5. Select details
  6. Confirm with the key’s owner that the fingerprint listed is correct

After you have carefully reviewed the fingerprint and verified its accuracy with the owner of the key, you may sign their key with your key. To do this:

  1. From the same window as above, select the Trust tab and press the Sign this key button.
  2. Sign the key, indicating how carefully you’ve checked the key. Selecting Not at all still allows you to use the key for email and data. You can also opt to be able to revoke your signature later or make it so that only you can see that you’ve signed the key.
  3. Press Sign.

You can now begin encrypting data that can only be decrypted by the key owner and establish a secure communication line between you and the key owner!

Using the Linux command line

This is based on the Ubuntu GPG Howto

Ensure that you have already set the right defaults

Please first review the OpenPGP Best Practices guide to ensure that you have set your defaults correctly. Do this before proceeding!

Generate an OpenPGP Key pair using GPG

Press Alt+F2 and type: gnome-terminal and then press enter

In the terminal, type: gpg --gen-key
which should return a menu similar to this:

Please select what kind of key you want:
  (1) RSA and RSA (default)
  (2) DSA and Elgamal
  (3) DSA (sign only)
  (4) RSA (sign only)

Select the type of key you want. RSA and RSA is the recommended type. (sign only) keys cannot be used for encryption.

Next, enter the key size you want. 4096 is recommended.

What keysize do you want? (2048)

Then enter the length of time that you would like the key valid for and then press y to confirm the expiration date. If you select 0, the key does not expire and will require to be revoked when you no longer wish to use it. It is recommended - to have your key expire within no more than 2 years.

Please specify how long the key should be valid.
     0 = key does not expire
   <n> = key expires in n days
   <n>w = key expires in n weeks
   <n>m = key expires in n months
   <n>y = key expires in n years
Key is valid for? (0)

Enter your name, email address. It is not recommended to use a comment. Your name and email address can be anything you want, not necessarily your real name or email address. If you want to use your OpenPGP key for encrypting email, put the email address you want to use with encryption in the “Email address” prompt.

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
  "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: John Q. Alias
Email address: the-email-youre-going-to-use@whatever.tld
Comment:

Now enter a strong password that you can remember. If you forget this password, it cannot be recovered and any encrypted data you have using it, including emails, will be permanently inaccessible. Hit enter when complete to begin generating the key.

Your OpenPGP public/private key pair has been generated!

List your keys

You can use this command to list your keys:
gpg --list-secret-keys

This should output data in a format like this:

sec   4096R/0xE361D8GH916EFH89 2014-05-14 [expires: 2016-05-14]
      Key fingerprint = 1234 5678 90AB CDEF GH01  2344 5678 9012 ABCE FGH1
uid                            John Q. Alias <the-email-youre-going-to-use@wherever.tld>
ssb   4096R/0x40339E25E2F2D99E 2014-05-14

Any reference to your KEY-ID below can be found using the first command and looking at the output. The line you’re looking at to find the KEY-ID is the sec line of each of the entries). The line contains sec, the key strength and type abbreviation (4096R in the first line), a slash, the KEY-ID, and then the creation date. The codebox below highlights the KEY-ID:

sec   4096R/0xE361D8GH916EFH89 2014-05-14 [expires: 2016-05-14]
            ^KEY-ID^
      Key fingerprint = 1234 5678 90AB CDEF GH01  2344 5678 9012 ABCE FGH1
uid                            John Q. Alias <the-email-youre-going-to-use@wherever.tld>
ssb   4096R/0x40339E25E2F2D99E 2014-05-14

So for this example, the KEY-ID would be E361D8GH916EFH89.

However, as discussed here you should not rely on the keyid! Instead, you should use your full fingerprint for all operations.

Export/Publish your public OpenPGP Key

  1. Press Alt+F2 and run gnome-terminal
  2. Create an ASCII armored version of your public key for exporting by typing:
    gpg --export -a <<fingerprint>> > mykey.asc

You’ve just exported your ASCII armored OpenPGP public key to the file mykey.asc in the folder you were in (your home directory, if you opened a new terminal). Now you can send the key to whomever you want to be able to encrypt files to you.

Publish your OpenPGP public key to a Key server

At this point, you can publish your public key to a key server where people can request it remotely to be able to send encrypted data and emails to you.

  1. Press Alt+F2 and run: gnome-terminal
  2. type gpg --send-keys <<fingerprint>>
    where <> is the fingerprint of the key you wish to publish on the key servers. Hopefully, you have already [[configured a good keyserver → /gpg-best-practices#selecting-a-keyserver-and-configuring-your-machine-to-refresh-your-keyring].

Windows

The windows version of this guide is out-of-date. If you are a windows user, you can help us update it! Please see our github repository for our help pages to learn how

It is not recommended to use Windows as a secure communication platform. While Windows can be locked down to provide a more secure environment than is provided by default, the tendencies in Windows lean towards very lax security. There is also a multitude of pre-built exploits for windows that make it easier for attackers to compromise. Here are some bullet points against using windows for secure communications:

  • widespread distribution of malware/trojans/viruses that could log key strokes, bypassing encryption schemes and/or logging other information
  • targeted hacking and malware installation is actively used by governmental agencies with Microsoft being most susceptible
  • Usually uses an unencrypted filesystem, main encryption tool is proprietary and cannot be scrutinized for exploits, back doors, or other weaknesses.
  • User accounts are administrators by default
  • Since Windows is proprietary and closed-source, there is no outside scrutiny for defects, back doors, or anything that “phones home”. You’re trusting Microsoft completely with whatever secrets you choose to put on your computer.

To ensure a secure communications platform, it’s recommended to install a GNU Linux free software distribution, like Debian (recommended), Ubuntu (beware privacy issues) or a derivate.

Install Gpg4win

Gpg4win is the recommended OpenPGP implementation for windows. It is Free Software, licensed under the GPL, with the source code available for modification or scrutiny.

  1. Download Gpg4win
  2. Double click the executable and begin the installation.
  3. Select the language you’ll be using.
  4. You’ll be greeted by the welcome screen. Press Next to continue.

  1. Next, you’ll be asked to agree to the GNU General Public License (the GPL license), which can be read in its entirety at GNU.org. If you accept, press Next.
  2. Choose the components you want to install. The default options are recommended. Claws-Mail is a powerful cross-platform email client available for Linux, Windows, Mac OS X, and others. GpgOL installs the plugin necessary to use OpenPGP keys with the Outlook mail client.

  1. Select the install folder (the default is recommended).
  2. Choose what shortcuts to create.
  3. Choose a name for any shortcut folders and then begin the installation. Choose to view the README file, or not, and then click finish.

Gpg4win is now installed and ready to use!

Create and Export an OpenPGP Public/Private Key pair

Kleopatra seems to be the more recent and more polished of the two Gpg4win key manager GUI frontends on Windows, so this guide recommends using that.

  1. Launch Kleopatra by the shortcut you installed (default: StartAll ProgramsGpg4winKleopatra)
  2. Click FileNew Certificate… or Ctrl+N.
  3. Press the Create a personal OpenPGP key pair button.
  4. Enter your name, email address, and a comment if you wish. Your name and email address can be anything you want, not necessarily your real name or email address. If you want to use your OpenPGP key for encrypting email, put the email address you want to use with encryption in the “Email address” box. When finished, click the Advanced Settings… button.

  1. In the Advanced Settings… dialog box, choose your key type and key strength. RSA, using key strength of 4,096 bits, for Signing and Encryption are recommended. When finished with the key settings, press OK to close the dialog box, then click Next.
  2. Review the information for the key, then press the Create Key button.
  3. Enter a strong password that you can remember. The password strength meter will give you a relative indication of how strong the password is. Getting 100% is strongly recommended. If you forget this password, it cannot be recovered and any encrypted data you have using it, including emails, will be permanently inaccessible.

Your key pair is now finished! From here, you can do one of the following:

  • Make a backup copy of your certificate (key)
  • Send the Certificate by email
  • Upload the certificate to a Directory Service (key server)
  • finish the wizard

It is recommended to upload the certificate to a directory service. This will upload your public key to a key server where it can be used by others to encrypt data and emails that only you can decrypt.

Find or Import someone else’s OpenPGP Public Key

If you want to be able to communicate with someone securely or encrypt data that only they can read, you need to import their public key into your keyring first.

Import from a key file

If someone exports their key to a file and sends it to you, you can import it into your keyring via Kleopatra by:

  1. Pressing the Import Certificates button, then
  2. Locating where you saved the key file, selecting it, and pressing the Open button.

The key that was stored in the key file has now been imported into your keyring!

Find on the key servers

  1. Navigate to FileLookup Certificates on Server… in Kleopatra
  2. Type some key words (a name or alias) to search the key servers. The best way to find someone is to search for their email address, as it’s uniquely tied to them.
  3. Select and review the keys that are returned to determine whether the key(s) returned belong to the person you’re looking for. You can review additional information about the key by pressing the Details… button.
  4. Once you’ve determined and selected the key(s) you want to import into your local keyring, press Import.

Their public key has now been imported into your keyring! Once you have verified the fingerprint (see above about why this is important), you may sign the key.

Sign their key (Certify their Certificate)

To do this,

  1. Click the Imported Certificates or Other Certificates tab.
  2. Right click the key you want to sign and click Certify Certificate…
  3. Select the user ID you want to certify and press Next
  4. Choose whether you want this certification to be visible to others or only to yourself and then press the Certify button.

You have now signed their key (certified their certificate) and are ready to begin encrypting data or emails that only they can decrypt!

Mac OS X

Unfortunately we have no MacOS version of this guide. If you are a MacOS user, you can help us update it! Please see our github repository for our help pages to learn how

It is not recommended to use Mac OS X as a secure communication platform. While there are fewer exploits and a better security model than windows, OS X has demonstrated a poor security patch speed in the past and has a large quantity of proprietary software and packaging, making it not capable of scrutiny for efects, back doors, or anything that “phones home”. Furthermore, it offers features that can be exploited by hackers or abused by governments or corporations. Some bullet points about OS X security:

  • Relies on a lot of proprietary software that can’t be modified or scrutinized by you
  • The webcam can be remotely turned on, offered as a “feature” if the laptop gets stolen, which could be abused or exploited to violate your privacy
  • Filesystem not encrypted by default and the primary tool available may have inadequate security.

To ensure a secure communications platform, it’s recommended to install a GNU Linux free software distribution, like Debian (recommended), Ubuntu (beware privacy issues) or a derivate.