GnuPG -- GNU Privacy Guard
GnuPG - General Info
Getting GPG
Setting Up GnuPG
gpg
, you will see:
[bob@yohost bob]$ gpg gpg: /home/bob/.gnupg: directory created gpg: /home/bob/.gnupg/options: new options file created gpg: you have to start GnuPG again, so it can read the new options fileThis is not your key pair, just the creation of your directory and options file
Generating Your Keys
Please select what kind of key you want: (1) DSA and ElGamal (default) (2) DSA (sign only) (4) ElGamal (sign and encrypt) Your selection?
Generating Keys, cont'd
DSA keypair will have 1024 bits. About to generate a new ELG-E keypair. minimum keysize is 768 bits default keysize is 1024 bits highest suggested keysize is 2048 bits What keysize do you want? (1024)
Generating Keys, cont'd
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)
Generating Keys, cont'd
You need a User-ID to identify your key; the software constructs the user id from Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter)"
Real name: Bob Smith Email address: bob@localhost Comment: User Bob You selected this USER-ID: "Bob Smith (User Bob)" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
Generating Keys, cont'd
Generating Keys, cont'd
Using Keys -- Your Keyring
~/.gnupg/pubring.gpg
and ~/.gnupg/secring.gpg
Using Keys -- Export A Public Key
--export
option to gpg--export
will dump your public key to STDOUT in binary format-a
for ASCII text. This is the public key format you are probably familiar with[bob@yohost bob]$ gpg --export -a -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org mQGiBD3+TlYRBAC6O6PixTdUYJkpINs+0GkG5LUJoMQ2EUwHZUCGSdrFPejhopj6 WTHgcl2w0IJwfIz+N8pjoQzdYuJ8/Qns87GdkBiAZuB2u5WaoHACJkfF1rwTOs1X uyg6cKXtju66pFEi4lNRcXNCQVdsuKWTxZDqohafgfVhGQ2BYlk9oah/TwCg1xED eKeicQQCjId3YGdsFlY7Q2kD/2bgKLUeeLviZdrkdH5kT1qCzxzMiI0ZDWacuV57 nBSUzECk+A4x4JQOfRJRtEMraOxkQzhOcmoB+TgMmFn3iJ/hYo+qediFnaVOMgRk VzcZ4dKRK7gYncXg8py3ASbfokJhCMCDCdmnMjSv9UYGX3++KZIkousez92PcWHO 9zi7A/9QG/GUuPZRsqvq23jIitsXQSNUPrBSZ+bHHp1E5Mc0Aqd/7jgE+mF+QVq5 aNWFA+ss2zZrsGrDz+mskiutVtgDBJ5y6NkPmecopmduoZUPMTwLnGMmIWT5UIsS hLs9+XMRlbG/cpovrrB27m7v0kLBKVs3D0dn8jbI0tDjn+ySu7QkQm9iIFNtaXRo IChVc2VyIEJvYikgPGJvYkBsb2NhbGhvc3Q+iFcEExECABcFAj3+TlYFCwcKAwQD FQMCAxYCAQIXgAAKCRBY4XYhMkCh+JhiAJ4rbXfrmsOtdHzsu6KQvE5QZZjx8ACg oknRXwARHnW6TiZbsXubB2GkbhC5AQ0EPf5OWRAEANlJFk1+p4RbF9KY0l3eDFXK OOr4VGq/ZDMooANHzczYT6HMawHd9oELnyvQ8jVE1ZslD2TTLXa/I42TihQkmAyQ LGWj4QrJiEm0mrYvMnz8TGp5rktBbudBFO8fGKLUWcZ1Mrz06P1A7HqAJU5VWDcl N3fgBUj/9r90PSHXrW37AAMGA/wMhE9Ox1lEGrBef9WEkzbL8icnfMpYM2v/WRMz Qda7lA/NMrmXcYkRRuyitpzYItP5+UbC9mxsdBXpZFxanQkD8rpPZSDWd37zvwh7 uicsYlhoG7bGPcbM7noOwEWSNraWeERQuaL4QwZ8sfKoy/TnbHrOw01dWfwDZM8v G83hoohGBBgRAgAGBQI9/k5ZAAoJEFjhdiEyQKH4L40AoKyWs1gGhFv4vGUS8jiv qIrJfjZaAKCMrq4Ug5BV0vVj0yRlQIgpYysOfw== =vNY2 -----END PGP PUBLIC KEY BLOCK-----
[bob@yohost bob]$ gpg --export -a Bobproduces the same output as above when bob has multiple keys in his keyring
Using Keys -- Import a Public Key
--recv-keys
option, bob gets the key directly from the server:
[bob@yohost bob]$ gpg --recv-keys --keyserver pgp.mit.edu DB42A60E gpg: requesting key DB42A60E from pgp.mit.edu ... gpg: key DB42A60E: public key imported gpg: /home/bob/.gnupg/trustdb.gpg: trustdb created gpg: Total number processed: 1 gpg: imported: 1
[bob@yohost bob]$ gpg --list-keys /home/bob/.gnupg/pubring.gpg ---------------------------- pub 1024D/3240A1F8 2002-12-16 Bob Smith (User Bob)sub 1024g/C16A012B 2002-12-16 pub 1024D/DB42A60E 1999-09-23 Red Hat, Inc sub 2048g/961630A2 1999-09-23
[bob@yohost bob]$ lwp-download http://www.linuxchick.org/pubkey.txt 1.33 KB received
[bob@yohost bob]$ gpg --import pubkey.txt gpg: key 7776E936: public key imported gpg: Total number processed: 1 gpg: imported: 1
[bob@yohost bob]$ gpg --list-keys /home/bob/.gnupg/pubring.gpg ---------------------------- pub 1024D/3240A1F8 2002-12-16 Bob Smith (User Bob)sub 1024g/C16A012B 2002-12-16 pub 1024D/DB42A60E 1999-09-23 Red Hat, Inc sub 2048g/961630A2 1999-09-23 pub 1024D/7776E936 2002-10-04 Mandi Walls sub 1024g/E0524E3E 2002-10-04
Using Keys -- Encrypting Data
hello.txt
[bob@yohost bob]$ cat hello.txt hello! how is the weather? it is freaking cold here.
--encrypt
option to encrypt the file:
[bob@yohost bob]$ gpg --encrypt hello.txt You did not specify a user ID. (you may use "-r") Enter the user ID: mandi@linuxchick.org Could not find a valid trust path to the key. Let's see whether we can assign some missing owner trust values. No path leading to one of our keys found. 1024g/E0524E3E 2002-10-04 "Mandi Walls" Fingerprint: C1A2 F26B 5714 4DC8 CD2A 1DAC F25E D76D E052 4E3E It is NOT certain that the key belongs to its owner. If you *really* know what you are doing, you may answer the next question with yes Use this key anyway? yes
hello.txt.gpg
which he can send to me and i can decryptgpg --encrypt -a hello.txt
, which will create a file called hello.txt.asc
Using Keys -- Decrypting Data
brrr.txt.asc
. This is another ASCII format file--decrypt
option to decrypt the message
[bob@yohost bob]$ gpg --decrypt brrr.txt.asc You need a passphrase to unlock the secret key for user: "Bob Smith (User Bob)(yes, bob's keys changed. i forgot his passphrase...)" 1024-bit ELG-E key, ID 8938F5F5, created 2003-01-29 (main key ID A9187B27) gpg: encrypted with 1024-bit ELG-E key, ID 8938F5F5, created 2003-01-29 "Bob Smith (User Bob) " It is very cold here. That groundhog better have good news tomorrow.
Using Keys -- Deleting Keys
[bob@yohost bob]$ gpg --delete-secret-key bob gpg (GnuPG) 1.0.6; Copyright (C) 2001 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. sec 1024D/3240A1F8 2002-12-16 Bob Smith (User Bob)Delete this key from the keyring? y This is a secret key! - really delete? y
[bob@yohost bob]$ gpg --delete-key bob gpg (GnuPG) 1.0.6; Copyright (C) 2001 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. pub 1024D/3240A1F8 2002-12-16 Bob Smith (User Bob)Delete this key from the keyring? y
[bob@yohost bob]$ gpg --list-keys /home/bob/.gnupg/pubring.gpg ---------------------------- pub 1024D/DB42A60E 1999-09-23 Red Hat, Incsub 2048g/961630A2 1999-09-23 pub 1024D/7776E936 2002-10-04 Mandi Walls sub 1024g/E0524E3E 2002-10-04 pub 1024D/A9187B27 2003-01-29 Bob Smith (User Bob) sub 1024g/8938F5F5 2003-01-29
Using Keys -- Revoking Keys
--gen-revoke
to create the certificate:
[bob@yohost bob]$ gpg --gen-revoke bob sec 1024D/A9187B27 2003-01-29 Bob Smith (User Bob)Create a revocation certificate for this key? yes Please select the reason for the revocation: 1 = Key has been compromised 2 = Key is superseded 3 = Key is no longer used 0 = Cancel (Probably you want to select 1 here) Your decision? Invalid selection. Your decision? 3 Enter an optional description; end it with an empty line: > Reason for revocation: Key is no longer used (No description given) Is this okay? yes You need a passphrase to unlock the secret key for user: "Bob Smith (User Bob) " 1024-bit DSA key, ID A9187B27, created 2003-01-29 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! -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org Comment: A revocation certificate should follow iEkEIBECAAkFAj44QwsCHQMACgkQ8iO+oKkYeyc57gCfaAAoa4WE8iT07euoYqBH eL9eRB4An1AsL3mWC4UI926xVKlJpJ1QqkFm =lCql -----END PGP PUBLIC KEY BLOCK-----
[bob@yohost bob]$ gpg --import -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org Comment: A revocation certificate should follow iEkEIBECAAkFAj44QwsCHQMACgkQ8iO+oKkYeyc57gCfaAAoa4WE8iT07euoYqBH eL9eRB4An1AsL3mWC4UI926xVKlJpJ1QqkFm =lCql -----END PGP PUBLIC KEY BLOCK----- gpg: key A9187B27: revocation certificate imported gpg: Total number processed: 1 gpg: new key revocations: 1
[bob@yohost bob]$ gpg --encrypt hello.txt You did not specify a user ID. (you may use "-r") Enter the user ID: bob No such user ID. Enter the user ID: bob@localhost No such user ID.
Using Keys -- Checking Signatures
wipe-2.1.0.tar.bz2.sig
, which contains the signature for the file:
[bob@yohost bob]$ cat wipe-2.1.0.tar.bz2.sig -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEABECAAYFAj1bJKAACgkQDrxthObLl9oQJwCgoyaEN6GZHSa2r6MSz45QJklY N+IAoIiu+nhilDEd7KFeMm8uE0RDJBnb =AVzd -----END PGP SIGNATURE-----
--verify
to verify the file:
[bob@yohost bob]$ gpg --verify wipe-2.1.0.tar.bz2.sig wipe-2.1.0.tar.bz2 gpg: Signature made Wed 14 Aug 2002 11:48:48 PM EDT using DSA key ID E6CB97DA gpg: Can't check signature: public key not found
[bob@yohost bob]$ gpg --recv-keys --keyserver pgp.mit.edu E6CB97DA gpg: requesting key E6CB97DA from pgp.mit.edu ... gpg: key E6CB97DA: public key imported gpg: Total number processed: 1 gpg: imported: 1
[bob@yohost bob]$ gpg --list-keys /home/bob/.gnupg/pubring.gpg ---------------------------- pub 1024D/DB42A60E 1999-09-23 Red Hat, Incsub 2048g/961630A2 1999-09-23 pub 1024D/7776E936 2002-10-04 Mandi Walls sub 1024g/E0524E3E 2002-10-04 pub 1024D/A9187B27 2003-01-29 Bob Smith (User Bob) sub 1024g/8938F5F5 2003-01-29 pub 1024D/9004BC23 2003-01-29 Bob Smith (User Bob) sub 1024g/B5577FFB 2003-01-29 pub 1024D/E6CB97DA 2002-02-26 Tom Vier uid Tom Vier sub 2048g/7A93AEDA 2002-02-26 [expires: 2004-02-26] [bob@yohost bob]$ gpg --verify wipe-2.1.0.tar.bz2.sig wipe-2.1.0.tar.bz2 gpg: Signature made Wed 14 Aug 2002 11:48:48 PM EDT using DSA key ID E6CB97DA gpg: Good signature from "Tom Vier " gpg: aka "Tom Vier " Could not find a valid trust path to the key. Let's see whether we can assign some missing owner trust values. No path leading to one of our keys found. gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. gpg: Fingerprint: DD7A 5403 4596 7F5D F2A4 7B6A 0EBC 6D84 E6CB 97DA
gpgv
command, which is a simplified version of gpg --verify
but works the same way
Using Keys -- Signing Files
gpg -b -a
:
[bob@yohost bob]$ gpg -b -a bob.tar.bz2 You need a passphrase to unlock the secret key for user: "Bob Smith (User Bob)" 1024-bit DSA key, ID 9004BC23, created 2003-01-29 [bob@yohost bob]$ ls bob.tar.bz2 hello.txt pubkey.txt wipe-2.1.0.tar.bz2 bob.tar.bz2.asc hello.txt.asc scripts.tar wipe-2.1.0.tar.bz2.sig brrr.txt.asc hello.txt.gpg tmp/
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQA+OYHF21hmipAEvCMRAjGSAKDPU3ibnas0WYE3yRMSRzkHrXzIqACfT/bF cUDHaiyAskl8eY1aPAKZ4mo= =JVfm -----END PGP SIGNATURE-----
[bob@yohost bob]$ gpg --verify bob.tar.bz2.asc bob.tar.bz2 gpg: Signature made Thu 30 Jan 2003 02:49:25 PM EST using DSA key ID 9004BC23 gpg: Good signature from "Bob Smith (User Bob)"
Using gpg -- Signing Keys
--edit-key
option:
[bob@yohost bob]$ gpg --edit-key mandi gpg (GnuPG) 1.0.6; Copyright (C) 2001 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. pub 1024D/7776E936 created: 2002-10-04 expires: never trust: -/q sub 1024g/E0524E3E created: 2002-10-04 expires: never (1). Mandi WallsCommand> sign pub 1024D/7776E936 created: 2002-10-04 expires: never trust: -/q Fingerprint: 62B9 6999 9988 B437 6E78 BD66 CD1D CAAA 7776 E936 Mandi Walls Are you really sure that you want to sign this key with your key: "Bob Smith (User Bob) " Really sign? yes You need a passphrase to unlock the secret key for user: "Bob Smith (User Bob) " 1024-bit DSA key, ID 9004BC23, created 2003-01-29 Command> save
--list-sigs
option. From the output from that command, bob can see tht he has successfully added his signature to my key:
pub 1024D/7776E936 2002-10-04 Mandi Wallssig 7776E936 2002-10-04 Mandi Walls sig A9187B27 2003-01-29 [User id not found] sig 9004BC23 2003-01-30 Bob Smith (User Bob) sub 1024g/E0524E3E 2002-10-04 sig 7776E936 2002-10-04 Mandi Walls
gpg --list-keys --with-colons
:
[bob@yohost bob]$ gpg --list-keys --with-colons /home/bob/.gnupg/pubring.gpg ---------------------------- pub:q:1024:17:219180CDDB42A60E:1999-09-23::64:-:Red Hat, Inc::scESC: sub:q:2048:16:C9CC699F961630A2:1999-09-23::64::::e: pub:f:1024:17:CD1DCAAA7776E936:2002-10-04::174:-:Mandi Walls ::scESC: sub:f:1024:16:F25ED76DE0524E3E:2002-10-04::174::::e: pub:u:1024:17:DB58668A9004BC23:2003-01-29::184:-:Bob Smith (User Bob) ::scESC: sub:u:1024:16:3A07B74EB5577FFB:2003-01-29::184::::e: pub:q:1024:17:0EBC6D84E6CB97DA:2002-02-26:2004-02-26:190:-:Tom Vier ::scESC: uid:q::::::::Tom Vier : sub:q:2048:16:AFB04D017A93AEDA:2002-02-26:2004-02-26:190::::e:
--list-sigs
command that Red Hat's key has been signed by several dozen other keys. He checks it out at pgp.mit.edu and sees the names of all the people who have signed Red Hat's key--edit-key
option, even though his key doesn't link back to Red Hat's key:
[bob@yohost bob]$ gpg --edit-key redhat gpg (GnuPG) 1.0.6; Copyright (C) 2001 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. pub 1024D/DB42A60E created: 1999-09-23 expires: never trust: -/q sub 2048g/961630A2 created: 1999-09-23 expires: never (1). Red Hat, IncCommand> trust pub 1024D/DB42A60E created: 1999-09-23 expires: never trust: -/q sub 2048g/961630A2 created: 1999-09-23 expires: never (1). Red Hat, Inc Please decide how far you trust this user to correctly verify other users' keys (by looking at passports, checking fingerprints from different sources...)? 1 = Don't know 2 = I do NOT trust 3 = I trust marginally 4 = I trust fully s = please show me more information m = back to the main menu Your decision? 3 pub 1024D/DB42A60E created: 1999-09-23 expires: never trust: m/q sub 2048g/961630A2 created: 1999-09-23 expires: never (1). Red Hat, Inc Command> save
Using Keys -- A Keysigning! A Keysigning!
[bob@yohost bob]$ gpg --fingerprint bob pub 1024D/9004BC23 2003-01-29 Bob Smith (User Bob)Key fingerprint = FC62 5CF4 8A83 4B10 54BA 8D40 DB58 668A 9004 BC23 sub 1024g/B5577FFB 2003-01-29
GPG and Email
Date: Fri, 31 Jan 2003 11:22:12 -0500 (EST) From: MandiOr it could be an attachment, with a message appearing at the bottom of the message:To: Subject: testing clearsign -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 testing clearsign -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://quantumlab.net/pine_privacy_guard/ iD8DBQE+OqK0zR3Kqnd26TYRAqA5AKCouIBErvDQd0mksC2rdyDJzy2TxgCg3XGZ Jsx4Tab7nz/9c9kglM23CfE= =ay+d -----END PGP SIGNATURE-----
Some Dude - somed@domain.org - sdude@other.net - http://www.other.net/~sdude Private personal mail: use PGP key 12345678; more sensitive data? Use 09876543 [ Part 2, Application/PGP-SIGNATURE 240bytes. ] [ Cannot display this part. Press "V" then "S" to save in a file. ]
More Information on Specific Email Clients
Other GPG Resources