GPG Quickstart Guide

Sunday, October 23

This is a quickstart, so let’s not waste any time. The first thing your going to need is a GPG Key, so fire up the terminal and from the command line, type:

$ gpg --gen-key

This will launch the GPG key-generation program. First you’ll be asked to select what kind of key you want: (1) DSA and Elgamal (default), (2) DSA (sign only), (5) RSA (sign only). If you want to sign and encrypt messages, DSA and Elgamal is what you want and is the default, so we’ll use that.

Next you’ll be asked to choose a keysize. A large keysize is more secure than a small one, but also takes longer for your computer to encrypt/decrypt data. The default value of 1024 is adequate, so we’ll use that. If you’re really paranoid, you can use 2048, which is currently gpg’s maximum.

You’ll then be asked to set an expiry date for your key. While expiry dates can be used for stronger security, you probably want your key to be valid indefinitely. Choose 0 (the default) to create a key that never expires and confirm your selection.

You need a user ID to identify your key. You’ll be asked for your Real Name, Comment and Email Address which will result in a user ID in this form: “Real Name (comment) <email@example.com>”. Go ahead an type in your user ID details and confirm your entry.

Finally you have to enter a passphrase. A passphrase is like a password, but is longer, can contain spaces, and is supposed to be impossible to guess. Think of a passphrase as a super-password. Use a long sentence, or a line from one of your favorite songs, spaces and punctuation included. Oh, and if you ever forget your passphrase, there is NO way to get it back.

All done? Congratulations! You now have a public and secret key in your keyring. To see all your keys, use the list-keys command:

$ gpg --list-keys

Create a revocation certificate

If you ever need to revoke this key (because, say, you forgot your long and difficult-to-guess passphrase), it helps to have a revocation certificate prepared. Right after creating a key is a good time to prepare a revocation, so let’s do it now.

$ gpg --gen-revoke packagethief > ~/revcert.asc

You’ll have to answer a few questions (the default answers are fine) and enter the passphrase you chose for your key. The above command will create your revocation certificate in the file revcert.asc. Now, keep in mind that if someone gets a hold of this revcert, they’ll be able to revoke your key and render all your encrypted messages unreadable. You probably don’t want this, so it’s a good idea to hide this somewhere OFF your computer. You could put it on another volume, save it to a disk and keep in somewhere safe, or just print it and keep it locked away in your filing cabinet. At the very least, you want to make sure that nobody except you can read it, so let’s change the permissions:

$ chmod u-w,go-r ~/revcert.asc
$ ls -l ~/revcert.asc
-r--------   1 packaget  packaget  260 Oct 23 10:30 revcert.asc

Now you (the owner) are the only one who can read the file. Note that we’ve even removed write permissions for the owner.

Using your key from within your mail program

Since most folks use a GUI-based email client like Thunderbird or Mail.app, here are some add-ins that you can use with your mail client to provide GPG functionality. These make it really easy to use GPG with your mail, adding sign/encrypt options to the Compose window and automatic decryption for encrypted messages.

  • Enigmail is an extension for Mozilla Thunderbird. If you use Thunderbird or Mozilla/Netscape, this is the cheese.
  • GPGMail is a plug-in for Apple’s Mail.app. Although its authors claim that “GPGMail is a complete hack, relying on Mail’s internal private API,” I’ve been using it for several months without issue. The latest version even has an installer.

The difference between signing and encrypting

Signing an email message using your key helps prove that the message came from you. This isn’t the same as encrypting the message, but is a common way to assert the authenticity of the sender. Your message is still sent in plain text and anyone can read it, but they can also use your GPG signature to verify your identity. I tend to sign most of the messages I send.

Encrypting is another story. To encrypt a message, you need the public key of the person to whom you are sending the encrypted message. When you use someone’s public key to encrypt a message, only the person who has the corresponding secret key can decrypt it. So, if I wanted to send an encrypted message to ‘John’, I would need his public key.

Obtaining your public key

To obtain your public key (a big block of ASCII characters that looks like garbage text), use gpg -a --export from the command line:

$ gpg -a --export packagethief

This will print your key to the screen (the -a option tells GPG to output in ASCII text). Sometimes it’s more useful to have this in a text file so you don’t have to copy/paste it. To do so, just redirect the output to a file:

$ gpg -a --export packagethief > ~/pubkey.txt

This will save your key in the file pubkey.txt in your home directory. You can now publish your key (say, on your website), so that others can use it to send you encrypted messages.

Changing your passphrase

Until today, I didn’t even know you could do this. You change the passphrase for a key by editing it. Not everything is editable (for example, you can’t change your user ID), but changing your passphrase is the kind of thing you might want to do from time to time.

$ gpg --edit-key packagethief
Command> passwd

You’ll be asked for your existing passphrase before you’ll be able to type a new one. To exit and save your changes, type quit at the prompt.

Related resources

My public key

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (Darwin)

mQGiBENbnh4RBAC7s8cQhyDkow6IgfIYpkflFQ5lmK8Hlcm8AR3Jcg2IsltBY+Z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/rOerPsAAwUH/2jNqxWexpvH5ZGwsWI2qBl5bghz
ofzTp4yxa/dj6LuU6rLfO4Rvob0avWjy8d2+b5ABvXfRM2BkZWjGP4s8sKJ1lRUM
pGfCw9N9ouraQMXyoG+R7/ZKQhECQipBRpm1l7T0VazQ/36RUEFBj2uEOoyv8H5H
uQ/s0/FQBZX2YU49vQ7ujBiutbRdedomx3dYw3kPpI9axagjGfJBgMhMOxZa0Dt8
pXico+KYFsXu26L3bacl73vSvCiqVRZfkDC06TvelR6yx/OGzxHPo6kFtjcUYGV1
wAHwdphcKd8Fy3+Xmi/Onpq4sXlBSL9IG1EW+eBISurCNOzsT2It8OVhun6ISQQY
EQIACQUCQ1ueJgIbDAAKCRCwvVj9bv2rJha9AJ4/FxF/ECoRvlV7w5MLVHnFv3PG
tACff4IWVTIMlABOm+o6aVfYliUUHb4=
=sLot
-----END PGP PUBLIC KEY BLOCK-----

Notes on Mail.app

Tuesday, September 27

When I first switched to the Mac, I installed and configured my favorite mail client, Thunderbird. OS X’s built-in mail client, Mail.app is (of course) gorgeous, and its tight integration with the OS is nice, but I was worried that it wouldn’t be up to snuff in its IMAP support, Spam filtering capabilities, and sorting features. Moreover, how I was going to use GPG to sign and encrypt my messages (a feature that’s easily added to Thunderbird by the Enigmail extension)? Well, my worrying was all in vain—as it turns out, Mail.app is more capable than I gave it credit for.

To be sure, Thunderbird has an impressive feature set: saved searches, message threading, Global Inboxes, and extension API to name a few. Well, as I found out, so does Mail.app. In fact, Mail.app has Smart Mailboxes which improve on saved searches, better threading features, and I even prefer the way multiple accounts are collected in the Global Inbox. In Thunderbird, you don’t get to group by individual accounts—they’re all just lumped together with no way to tell which is which without looking at the to header.

Spam filtering in Mail.app is just as good (if not better) than it is in Thunderbird, both of which use Bayesian filtering and cumulative rules to ‘learn’ what you consider to be Spam. Mail.app gets bonus points, however, because you can manually set additional rules in the same way you would filters to futher customize and refine things.

As for GPG (a feature I can’t do without), GPGMail for Mail.app is the answer I was looking for. For those who aren’t aware, GnuPG is a free PGP replacement. PGP stands for “Pretty Good Privacy”, and can be used to encrypt text (usually e-mail) and sign messages thus proving the identity of the original author. Simply put, GPGMail allows you to read and send PGP authenticated and/or encrypted messages right from inside Mail.app.

If anything, I’d say Mail.app has a more complete feature set than Thunderbird, although the latter makes up for this by virtue of its extension capabilities. That said, I use an extension in Thunderbird that adds a toolbar button to toggle normal/full headers of messages - in Mail.app, this feature exists out of the box. There’s also a toolbar button that toggles between threaded and un-threading message viewing - something I’ve always wished Thunderbird could do (and for which no extension exists).

Thunderbird is still highly regarded in by book due to the fact that it’s cross platform and open source (when you’re working on Mac, Windows, and Linux, it’s nice to have the same mail client accross the board). If Thunderbird were to improve its Mac support in a few areas, and were to support true OS X aqua theming, I would probably be using it in place of Mail.app for the reasons aforementioned. Sadly, it just feels out of place in an otherwise tightly knit environment. That said, Thunderbird (and Firefox for that matter) really shine on Linux—fast, responsive, and good looking.

A few tips

  • To add multiple email address for an account in Mail.app: In the Preferences for the account, enter all your addresses in the email address field, separated by commas. When composing a new message, you’ll get to select which address you’d like to use in the from header.
  • If you’re down with GPG, you might also be interested in the Mac GPG project which brings a bunch of GUI tools to OS X. Check out GPG Keychain Access which lets you manage and create keys using a friendly GUI, and GPGPreferences for a pretty preference pane in which you can manage GPG’s option file.