Tech Tip: Encrypt Files with GPG
Encrypting files from the command line is simple with gpg. You can use it to encrypt and decrypt files with a password.
The command gpg is part of GnuPG. GnuPG stands for GNU Privacy Guard and is GNU's tool for secure communication and data storage. It can be used to encrypt data and to create digital signatures. It also includes an advanced key management facility. GnuPG works on Linux and UNIX like operating systems as well as for Windows and Mac OS X.
To encrypt a single file, use the -c command line option with gpg. For example, to encrypt the file myfinancial.info, use the command:
$ gpg -c myfinancial.info Enter passphrase: YOUR-PASSWORD Repeat passphrase: YOUR-PASSWORD
This will create the file myfinancial.info.gpg. Note that the original file is not deleted, so once you feel safe encrypting and decrypting files, you probably want to delete your unencrypted versions of the files. Also note that depending on your system's configuration, gpg may ask for passphrases in pop-up windows rather than at the command line.
The -c option tells gpg to encrypt with a symmetric cipher. Caution: don't forget your passphrase (password), there is no way to recover data with out the passphrase.
To decrypt the file, use the command:
$ gpg myfinancial.info.gpg gpg: CAST5 encrypted data Enter passphrase: YOUR-PASSWORD
If you want to write the output to a different file, use the -o command line option:
$ gpg –o myfin.info.txt myfinancial.info.gpg
If you'd rather have a "text" file, rather than a binary file, use the -a option to gpg:
$ gpg -c -a myfinancial.info Enter passphrase: YOUR-PASSWORD Repeat passphrase: YOUR-PASSWORD
This will create the file myfinancial.info.asc rather than myfinancial.info.gpg.
- Handling the workloads of the Future
- Readers' Choice Awards 2014
- diff -u: What's New in Kernel Development
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- Synchronize Your Life with ownCloud
- Days Between Dates?
- Cooking with Linux - Serious Cool, Sysadmin Style!
- Non-Linux FOSS: Don't Type All Those Words!
- Computing without a Computer
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane