GNU pgp

June 30th, 2010 | rpickett | Technical

Here are some notes on GNU pgp from my recent experience at setting up a secured way to share a password file with multiple users.

For those that want to send me encrypted data, here’s my private key ID: F7C6134C

Creating your key:

# gpg --gen-key
(1) DSA and Elgamal (default)
What keysize do you want? (2048) 4096
Key is valid for? (0) 5y
Is this correct? (y/N) y
Real name: <YOUR NAME>
Email address: <YOUR EMAIL>
Comment: <YOUR COMMENT>
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
Passphrase: <your password – make it strong>
Reenter Pasphrase: <enter it again>
It will print out something like this (note this key is completely fictitious - don’t try to use it):
pub 1024D/434E3134 2010-06-25 [expires: 2015-06-24]
Key fingerprint = F895 333A 41C2 27E3 A5F0 DF44 9F33 ECD7 434E 3164
uid <your info here>
sub 4096g/F71105C7 2010-06-25 [expires: 2015-06-24]
On the first line, this number “434E3134″ is your key id – you’ll need it to publish it for others to retrieve it.

Now set that key to be your default key:

# vim ~/.gnupg/gpg.conf

add this line:

default-key <YOUR KEY ID>

Now publish your key for others to use:

# gpg --send-keys --keyserver keyserver.ubuntu.com <YOUR KEY ID>

If you want to download someone else’s key to use:

# gpg --recv-keys --keyserver keyserver.ubuntu.com <THEIR KEY ID>

To sign someone else’s key:

# gpg --sign-key <THEIR KEY ID>

and re-publish it so they can get your signature on it:

# gpg --send-keys --keyserver keyserver.ubuntu.com <THEIR KEY ID>

Don’t forget to --recv-keys after someone has signed your key – use your own key ID.

To encrypt and sign a file:

# gpg -esr <THEIR KEY> --out <ENCRYPTED FILE>.gpg <ORIGINAL FILE>

To view the contents of an encrypted file:

# gpg -d <ENCRYPTED FILE>

This will prompt for you key password and also show you the person who sent you the file

To export your private key:

# gpg --export-secret-key <KEY ID> > private.key

To import a private key:

# gpg --allow-secret-key-import --import private.key

NOTE: Exporting an importing private keys does not make them usable without the password. You’re safe to export your private key and store it publicly, no one can use it without the password.


Leave a Comment