Encrypt and decrypt files with a password

From ezUnix
Jump to: navigation, search
                                    pdf_icon.png Download this article as a single PDF document 

Introduction

To encrypt and decrypt files with a password, use gpg command.
It is an encryption and signing tool for Linux/UNIX like operating system such as various BSDs, Mac OSX or Solaris.

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 includes an advanced key management facility.


Encrypting a file

To encrypt single file, use command gpg as follows:

# gpg -c filename

For example, to encrypt mysecretl.info file, type the command:

# gpg -c mysecret.info

Output:

Enter passphrase:<YOUR-PASSWORD>
Repeat passphrase:<YOUR-PASSWORD>

This will create a mysecret.info.gpg file.
The -c switch means: Encrypt with symmetric cipher.


NOTE: Be careful! If you ever forget your password, you won't be able to recover the data as it uses very strong encryption.


Decryption

To decrypt your encrypted file use following gpg command:

# gpg myfinancial.info.gpg


The uutput will look as follows:

# gpg mysecret.info.gpg
gpg: CAST5 encrypted data
Enter passphrase:<YOUR-PASSWORD>

To decrypt file and write output to file somefile.txt you can run command:

# gpg mysecret.info.gpg –o somefile.txt

NOTE: If file extension is .asc, it is a ASCII encrypted file and if file extension is .gpg, it is a binary encrypted file.


Links

GnuPG - the GNU project's complete and free implementation of the OpenPGP standard.



Cheers,
Marcin


<comments />