How to encrypt a file with gpg

chris (2007-10-29 18:15:42)
3700 views
0 replies
I always have to look up how to use gpg to pgp encrypt a file. So hopefully noting this here will save me trawling the gpg man page for the exact command to encrypt - and maybe it'll save somebody else some time also.

So first you will need to ask the recipient of your encrypted file to send you their public key. You will use their public key to encrypt the file before sending it over to them. They will also have to have a copy of your own public key in order to be able to decrypt the file sent by you. So first, use gpg --list-keys to list the keys you have on your local keyring. You can then tell gpg who you want to encrypt the file for.
chris@localhost:  gpg --list-keys

/home/chris/.gnupg/pubring.gpg
------------------------------
pub   1024D/E90AGB24 2007-10-18
uid                  fred flintstome (fflint pgp) <fred@flingstone.com>
sub   2048g/03AFA77C 2007-10-18

pub   1024D/E50BGB34 2007-10-18
uid                  wilma flintstome (wflint pgp) <wilma@flintstone.com>
sub   2048g/03AFA77C 2007-10-18

Those aren't real key entries, but they do show what the output of the gpg list keys command should look like.

Now you can just encrypt the file you want to send. Let's say you want to encrypt spreadsheet.xls, this is the command you would use to encrypt that for wilma.
chris@localhost: gpg --encrypt --recipient "wilma flintstone" spreadsheet.xls
chris@localhost:

This will create an encrypted version of the file called spreadsheet.xls.gpg. All you need to do is attach that to your email and you're done.

For more information on gpg encryption and signing, specifically with the Evolution mail client, check out this document on Using Evolution for Email Encryption and Signing

christo
comment