linuxdot.org Linux Expo Birmingham 2002
Linux news | Newbie's Linux manual | Linux links | Link us
The Linux columns | Book reviews
  DistroWatch + TuxReports October 28, 2002

The quick GnuPG guide

Laurence Hunterby , 18 November, 2001

In my last column I dealt with PGP. This week it's the open, patent-free alternative, GnuPG's turn. For a brief introduction on encryption, and specifically public key encryption, see my last column.

Unlike PGP there's a good chance GnuPG (GNU Privacy Guard) is already installed. To find out, enter:

gpg --version

...and if version information is displayed you're in luck.

Installation

If GnuPG's not installed, download the compressed tarball here. (GnuPG 1.0.6, the latest version at the time of writing, is 1.9Mb.)

Open a terminal window, or at the console, and in your normal everyday user account (with knowledge of the root password to install software), cd to the directory you downloaded GnuPG to, and enter:

tar xvfz gnupg-1.0.6.tar.gz
cd gnupg-1.0.6
./configure
make
su -c 'make install'

Key generation

To generate your public and private key pair, enter:

gpg --gen-key

...and when prompted, enter as follows in blue, changing the name and email address (the first three prompts you can just press Enter for):

You'll find your keys stored in the ~/.gnupg directory.

Exporting public key

GnuPG keys are stored in binary format. To email your public key to others, you need to export it in text (ASCII armor) format. To do so, enter:

gpg -ao mypubkey.gpg --export

...(-a for armor, -o for output, followed by the name of the text file to output it to).

Adding a public key

To add a public key to your key ring, after receiving and saving it, enter:

gpg --import bills_key.gpg

To sign (or edit) a key, enter:

gpg --edit-key

...which will put you at the GnuPG prompt. For help, enter 'help' (or '?'), to display the public key's fingerprint for authentication, enter 'fpr', and to sign it as authentic, enter 'sign'. To quit, enter 'quit'.

Encrypting a file

In my last column, I had shown you how to use PGP with KMail to encrypt email. For GnuPG the same instuctions apply. And as with PGP, email attachments are not encrypted, and must be encrypted separately, and then attached.

To encrypt a file, in this case report.txt, enter:

gpg -r -e report.txt

...to create the encrypted file, report.txt.gpg. (-r for recipient, -e for encrypt.)

Decrypting a file

To decrypt a file, in this case report.txt.gpg, enter:

gpg -o report.txt -d report.txt.gpg

...to create the unencrypted file, report.txt. (-o for output, -d for decrypt.)

Alternatively, to decrypt and send to standard output, enter:

gpg -d report.txt.gpg

A few more things

For more on GnuPG, see the gpg man page. For a brief list of GnuPG's options, enter:

gpg --help

To list keys, enter:

gpg --list-keys

And to list fingerprints, enter:

gpg --fingerprint

About us  
Latest stable kernel: 2.4.19 | Latest development kernel: 2.5.44
Copyright © 1998-2002 Linuxdot.org.
Linux ® is a registered trademark of Linus Torvalds.