Learning how to protect your files with GnuPG on Linux should be of utmost importance for any conscious user. If that’s you, then we’re here to guide you through the entire process.
This article will discuss how to password-protect Linux files using GnuPG. It is essential to understand why encryption is necessary. An encrypted file can be shared between colleagues and professionals. This can lead to improved security and privacy. We’re here to talk about achieving security and privacy using GnuPG.
In this article, we will first discuss GnuPG, along with public key cryptography. Then, the installation of GnuPG software with the process of encrypting and decrypting a file using the GnuPG utility.
Introduction to GnuPG
The term GnuPG stands for GNU Privacy Guard. It comprises programs to perform public key encryption and digital signature. It can be used to protect and keep your secrets safe. The intended recipient can only decrypt a file encrypted using GnuPG. It is based on pretty good privacy (PGP), written in 1991 by Phil Zimmerman. The following are the core features of GnuPG:
- It is free and completely implements OpenPGP standards. The standard is defined by RFC4880
- It can be used to sign and encrypt any type of communication
- It provides access modules for public key directories
- It includes support for key management
- It can be integrated with various other modules
Public key cryptography
GPG is based on public key cryptography that requires two keys, i.e., the public key and the private key. The public key can be shared and known to another person. However, you must keep your private key to yourself.
Encrypting a file using public key cryptography
To send a file to the recipient, you will use your private key and the recipient’s public key to encrypt. Encrypting the recipient’s private key will ensure that no one else other than the recipient can decrypt it. Encrypting with your private key will ensure that file contents have not been changed while sending.
Decrypting a file using public key cryptography
To decrypt a file, the recipient will need his private key and the sender’s public key to decrypt the file. Note that there is no harm in sharing the public key.
Installation of GnuPG
Before proceeding towards protecting a file using GnuPG, we will first install the GnuPG using the apt package manager. Follow the steps below to install.
Update your system
The first step is to update your system. Open your Terminal and type the following command:
$sudo apt update
Also, type the following command to upgrade:
sudo apt upgrade
Then, install the GnuPG with the following command:
$sudo apt install gnupg
Verifying the installation
After the installation of GnuPG, you can verify the installation by checking its version with the following command:
You should see the version of GnuPG as output. After installing GnuPG, you can use it to protect your files.
Usage of GnuPG
The usage of GnuPG is straightforward. You can encrypt any file to protect it by using the following command:
$gpg -c [file]
Protecting a file using encryption
As an example, the following command protects a file:
$sudo gpg –c file.dat
When you run the above command, the system will ask you for a password.
Note: To ensure strong protection, provide a password of at least 8 characters.
It will take a while, after which a .gpg file will be created.
GnuPG encryption algorithms
In older versions, GPG uses the CAST5 algorithm for encryption. In a recent version, AES has been embedded. Block ciphers are available in GPG software: AES128, AES192, and AES256. To select a particular encryption algorithm for encrypting files, use the following command:
$ gpg -c --cipher-algo AES256 file.txt
Here, we have used the AES256 cipher.
Decrypting a file
To see the file’s contents, you have to decrypt it again. You can move the file to another folder and then decrypt it using the following command:
$sudo gpg [file.gpg]
Now, you can view the content of the file. For instance, if the file contains text content, you can view it using the following command:
Encryption and decryption using the graphical user interface (GUI)
Besides the command line interface, there are options for encrypting and protecting a file using the graphical user interface. There are a number GUI based tools, such as Seahorse. It is a GNOME-based utility for managing SSH, PGP, and password-related encrypted files. For interested readers, the exact details of encryption and decryption can be seen in the documentation of this tool.
In this article, we have discussed the GnuPG utility. It can be used to encrypt and decrypt the file. Privacy is an essential objective of any digital system. We have discussed GnuPG, how we can install GnuPG, and how we can encrypt or decrypt any file using GnuPG. We have discussed the process of encryption and decryption for command line utility. Besides, there are graphical user interfaces for doing the same job through an interactive user interface.
If this guide helped you, please share it.