Introduction
Encryption encodes files so that only authorized users can access them. While encryption doesn’t prevent interception, it ensures that intercepted files remain unreadable without the decryption key. This article covers three standard encryption tools available on Linux, including their use for encrypting, decrypting, and password-protecting files.
1. GnuPG
GnuPG (GNU Privacy Guard, or GPG) is commonly included in Linux distributions. If it’s not installed, you can add it via your package manager:
- Ubuntu/Debian:
sudo apt-get install gnupg
- CentOS/Fedora:
yum install gnupg
Encrypting:
To encrypt a file, use the following command:
gpg -c /path_to_the_file/testfile.txt
You’ll be prompted to enter a passphrase twice. This creates an encrypted file named testfile.txt.gpg
. For a list of available encryption algorithms, run:
gpg --version
Decrypting:
To decrypt the file, use:
gpg /path_to_the_file/testfile.txt.gpg
You’ll need to provide the same passphrase used for encryption.
More information: GnuPG Official Site
2. Zip
The Zip format is widely used and supports encryption with the pkzip stream cipher.
If Zip is not installed, add it with:
- Ubuntu/Debian:
sudo apt-get install zip
- CentOS/Fedora:
yum install zip
Encrypting:
To create an encrypted zip file, use:
zip --password mypassword testarchive.zip testfile.txt
To add more files:
zip --password mypassword testarchive.zip testfile.txt testfile1.txt testfile2.txt
Decrypting:
Install unzip if it’s not already available:
- Ubuntu/Debian:
sudo apt-get install unzip
- CentOS/Fedora:
yum install unzip
To decrypt, use:
unzip testarchive.zip
You’ll need to enter the password used during encryption.
3. OpenSSL
OpenSSL is typically included in most Linux distributions. If needed, install it with:
- Ubuntu/Debian:
sudo apt-get install openssl
- CentOS/Fedora:
yum install openssl
Encrypting:
To encrypt a file with OpenSSL, use:
openssl enc -aes-256-cbc -in /path_to_the_file/testfile.txt -out /path_to_the_file/testfile.dat
Explanation of each option used in the above command.
enc encryption
-aes-256-cbc the algorithm to be used.
-in full path of a file to be encrypted.
-out the full path where it will be decrypted.
Decrypting:
To decrypt the file, use:
openssl enc -aes-256-cbc -d -in /path_to_the_file/testfile.dat > /path_to_the_file/testfile2.txt