Unceremoniously ganked from here:
First, generate a keypair by running gpg --gen-key and follow the prompts using the defaults. gpg complained about there not being enough random bytes available. As I was doing this remotely, I had to open a new shell into the machine and do things like du -sh /, and find / ... Also, at the end of it I got an error message:
gpg: no writable public keyring found: eofKey generation failed: eof
To fix this, I had to
rm -rf ~/.gnupg && mkdir ~/.gnupg && chmod 0700 ~/.gnupg
Next, we have to generate a revocation certificate (in case we forget our passphrase or our key's been compromised) using gpg --output revoke.asc --gen-revoke "Your Name"
[dmentis@mail ~]$ gpg --output revoke.asc --gen-revoke "David Mentis"
sec 1024D/9DA1B8E1 2007-05-17 David Mentis <davidmentis@emailhost.com>
Create a revocation certificate for this key? y
Please select the reason for the revocation:
0 = No reason specified
1 = Key has been compromised
2 = Key is superseded
3 = Key is no longer used
Q = Cancel
(Probably you want to select 1 here)
Your decision?
Enter an optional description; end it with an empty line:
> Revoking my key just in case it gets lost
>
Reason for revocation: Key has been compromised
Revoking my key just in case it gets lost
Is this okay? y
You need a passphrase to unlock the secret key for
user: "David Mentis <davidmentis@emailhost.com>"
1024-bit DSA key, ID 9DA1B8E1, created 2007-05-17
ASCII armored output forced.
Revocation certificate created.
Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable. But have some caution: The print system of
your machine might store the data and make it available to others!
Next, export your public key using gpg --armor --output public.gpg --export yourid@your.host.com. This will store your public key in public.gpg, if you want to put it on your website or mail it.
Now, encrypt the pw file with gpg --armor --output pw.gpg --encrypt --recipient yourid@your.host.com pw, which will encrypt the pw file as pw.gpg. To decrypt it, you must include your own key in the --recipient list.
Test decrypting the pw file with gpg --output testpw --decrypt pw.gpg.