How to Use GPG to Encrypt and Decrypt Files
Posted on April 17th, 2009 by Gabriel HarperA good friend recently provided me with some dead-simple instructions on how to use GPG in linux so we could share a few sensitive files. I have edited them slightly and with his permission I will share them with you.
To encrypt a file for someone you first need to import their public key:
gpg –import key_file_to_import
Then you can encrypt a file for them to decrypt, like this:
gpg -r [email protected] -a -e file_to_encrypt
You’ll end up with file_to_encrypt.asc, and that’s the file you send them.
You could also encrypt data right from stdin, like this:
gpg -r [email protected] -a -e > outputfile.asc
Then type the information to be encrypted, and hit ctrl+d when done.
There are also GUI tools like the Enigmail plugin for Thunderbird to make it nicer, but the command line isn’t really too bad.
Oh yeah, and if you want someone to be able to encrypt stuff to send you, they need your public key. Here’s how to export it:
gpg -a –export > your_key.asc
Then send them your_key.asc.