AS we know, now a days it’s not safe to send and receive data over internet. There are many option available to secure your data while traveling over internet. GnuPG also provides you to encrypt your data on key basis and transfer them securely over internet. GPG is an encryption and signing tool for UNIX/LINUX like OS. GnuPG provides many methods for file encryption and decryption. click here to read more about GnuPG.
This article will help you about File Encryption using GPG key on linux system.
Step 1: Create Test File
Firstly create a test file to encrypt. you may skip this step if you want to encrypt existing file.
# echo "Enter file content here" > secureit.txt
Step 2: Encrypt File using GPG
Let use following command to encrypt above created file using gpg.
# gpg -c secureit.txt
Above command will create a encrypted file named secureit.txt.gpg. Original file will remain same.
# ls -l -rw-r--r-- 1 root root 24 Mar 9 21:36 secureit.txt -rw-r--r-- 1 root root 74 Mar 9 21:36 secureit.txt.gpg
Step 3: Decrypt File
Now its also required to decrypt encrypted. Use following command to decrypt file again.
# gpg -o secureit-new.txt -d secureit.txt.gpg gpg: CAST5 encrypted data Enter passphrase:
You will get a new decrypted file named secureit-new.txt.
# ls -l secureit-new.txt -rw-r--r-- 1 root root 24 Mar 9 21:56 secureit-new.txt