GnuPG is a free and open source OpenPGP compatible encryption system. Using GnuPG, you can easily encrypt the important and confidential files and documents. In this article we will see how to encrypt and decrypt files using GnuPG in your Ubuntu Linux system.
How to Install GnuPG on Ubuntu
GnuPG comes pre-installed by default in Ubuntu. If not then install it using below command in terminal application.
sudo apt install gnupg
You can check the installed GnuPG version using below command.
How to Encrypt Files Using GnuPG
To encrypt a file using GnuPG, you need to run command like below. You will be prompted to enter a password twice to secure the file.
gpg -c yourfile.txt
Here i am going to encrypt yourfile.txt file in my Home directory. Just replace “yourfile.txt” with your real file name and path.
The above command now created a new encrypted file has the same name, but with the extension .gpg added like below.
The original file is left intact.
How to Decrypt Files Using GnuPG
To decrypt the file (in my case “yourfile.txt.gpg” file) just run below command. Before running that command just delete the original file. (example: yourfile.txt in my case) to test it.
It will ask the password. Just enter the correct password. It will decrypt the file yourfile.txt.gpg with the same name but without the .gpg extension (yourfile.txt). Also, the encrypted file is left intact.
In this way you can encrypt and decrypt files using GnuPG in Ubuntu.
For more details about GnuPG, run below command.