How to Encrypt Files on Linux?

With the increasing number of cyber attacks every day, it’s very important to secure our systems and files. In Linux, this task can be performed by encrypting our OS, certain drives or partitions, or simply files and directories.  Almost all the latest Linux distributions provide an option to do so. However, some of them offer third-party applications to do so.

This guide illustrates the possible aspects of encrypting files in Linux. The guideline of this post is as follows:

Method 1: Encrypting Files Using the “GnuPG” Tool

The “GnuPG” also known as “GNU Privacy Guard” is a free and open-source software utility. It allows Linux users to “encrypt/decrypt” files and provides “signing services” using the command line. It was developed by the “Free Foundation Software” and is pre-installed into most of the Linux distributions.

However, if it is not installed, then use the following commands to install it into the desired Linux distributions:

$ sudo yum install gnupg                             # For RHEL/Fedora
$ sudo apt install gnupg                             # For Debian-Based/Ubuntu

Example 1: Using the GPG Public Key

To start the encryption process first have a look into the “File1.txt” file located in the “Documents” directory having the following content:

$ cat File1.txt

Now execute the the “gpg”  command followed by “-c” option to encrypt the “File1.txt” file in this way:

$ gpg -c File1.txt

Once the “Enter” key is pressed it asks for the “passphrase” that is the encryption password. Type the encryption password and for re-confirmation, retype it again in the next field:

The user can also save the password in the “password manager” by marking the checkmark shown in the above image.

The “File1.txt” has been encrypted now and saved in the present working directory “Documents” with the new extension format like “File1.txt.gpg” as shown below:

The user can view the “File1.txt.gpg” encrypted file content using the “cat” command:

$ nano File1.txt.gpg

As the output shows the garbage data and can’t be readable for the user.

Example 2: Using the GPG Private Key

Generally, the “Gnu” works on the “public” and a “private” key. The “public” key can be sent to everyone, but the “private key” is used for secret purposes, and without it, the user can’t decrypt any file that is encrypted by the “public” key.

Execute the following command in the terminal (Ctrl+Alt+T) to generate a private key. It will ask you the “Real name” and the “E-mail address”. Fill in both the fields and type “O(okay)” to continue the process:

$ gpg --gen-key

After that, the console asks for the password. Enter the password and confirm it after retyping into the next field and pressing the “OK” button:

Once the password is set, the prompt shows that the private key has been created, as shown in the below image:

Now use the following command with the above “real name” or the “E-mail address” to encrypt the “sample.txt” file:

$  gpg -e -r 'annna' sample.txt

Here the “sample.txt” has been encrypted to “sample.txt.gpg” with a private key of user “annna

Method 2: Encrypting Files Using the “Nautilus” tool

The “nautilus” is the file manager that works on the Gnome desktop environment. Its main objective is to create files and folders and show data. It is also beneficial to encrypt or decrypt the file for the Linux user who is facing difficulties using the command line interface.

First, install it according to your Linux distributions by utilizing the following commands:

$ sudo snap install nautilusfilemanager --edge       # For Snap Enabled Distros
$ sudo apt install seahorse-nautilus                 # For Debian-Based/Ubuntu

Note: When the installation is complete then restart the “nautilus” using the below-mentioned command:

$  nautilus -q

Now move on to the usage of “nautilus” for the encryption of files on Linux. For this purpose, follow the step-by-step guidelines that are described below:

Firstly, open the desired file that the user wants to encrypt. In this case, the “Extra.txt” file that is available in the “Pictures” directory is selected.

Right-click on it and click on the “Encrypt” option from the drop-down menu list:

The “Encrypt” option pops up a new “Encryption settings” window that contains two options.

  • Use passphrase only” option asks for the new encryption password.
  • Choose a set of recipients” option that contains the private key that is already created in the above “GnuPG” method.

We marked the second option and used the key ID “694277b7” associated with the email address “[email protected]

Once we pressed the “OK” button the “Extra.txt” has been encrypted to the file “Extra.txt.pgp” as shown in the image:

Method 3: Encrypting Files Using the “Archive Manager” tool(GUI)

Another simple tool to encrypt the files in Linux is the pre-installed Archive Manager”. This tool is typically an archive manager of the Gnome desktop that creates, modifies, and unpacks the archive files. However, in this method, we are utilizing it for the encryption of files.

To perform this task open right-click on the file that the user wants to encrypt and hit the “compress” option located in the popup menu list:

A new dialogue box “Create Archive” will pop up. Click on the “Create” button to simply create the compressed “File3.txt” archive having extension “.zip”:

After that, open the created “” archive by double-clicking on it.  Hit the “hamburger” icon shown in the menu bar of the “” window. It generates a drop-down list with a list of options. Click on the “Password” option from the list:

Type the password for encryption and “save” the encrypted “” with the specified password:

Hence the “” has been encrypted and the user will require the setup password and the time of extraction or decryption:

The above output shows that the file has been encrypted.


Linux files can be encrypted using “GnuPG” and the “Nautilus” software file manager tool. The “nautilus” tool provides a graphical user interface for the encryption of files. The user can also perform this task using the default “Archive Manager” application. This guide has provided all the possible ways to encrypt files on Linux.