How to encrypt/decrypt files in Linux
Linux is great for creating the most secure system you will work on. there are quite a few tools meant to protect your data.
Some tools are built into the operating system, while others must be installed.
Thus, lets see up next how to encrypt and decrypt files with a password in Linux.
Encrypt files with a GUI
Another useful tip on how to encrypt files with a password in Linux is to use a graphical tool that features a Nautilus file manager.
You can encrypt/decrypt files with a right-click on the target file.
Type the command sudo apt-get install seahorse-nautilus -y
, and after the installation process is done, restart Nautilus with the command nautilus -q.
From this point on, all you have to do is right click on the file you want encrypted and click the encrypt function.
Encrypt files with gnupg
GnuPG represents a tool useful for securing both communication and data storage. It is great for encrypting files/folders and for designing digital signatures. This tool comes with a professional key management option.
Install gnupg
GnuPG can be installed in Debian, Ubuntu or Mint Linux with the following command:
$ sudo apt-get install gnupg
For Red hat or CentOS Linux you will have to use the command -
$ sudo yum install gnupg
For Fedora Linux you will have to use the command -
$ sudo dnf install gnupg
For Arch Linux you will have to use the command -
$ sudo pacman -S gnupg
For OpenSUSE Linux you will have to use the command -
$ sudo zypper install gpg2
For FreeBSD unix you will have to use the command for the port -
# cd /usr/ports/security/gnupg/ && make install clean
and add the package via
# pkg install gnupg.
For OpenBSD unix you will have to use the command -
$ doas pkg_add gnupg
How to use GPG
After this, you can start encrypting your data in either Linux or Unix, with the aid of the following commands:
A single file requires the command -
$ gpg -c filename
A myfinancial.info.txt file requires the command -
$ gpg -c myfinancial.info.txt
On the other hand, to decrypt data in Linux or Unix systems, you can use one of the following commands:
$ gpg myfinancial.info.txt.gpg
$ gpg -d myfinancial.info.txt.gpg
$ gpg --decrypt myfinancial.info.txt.gpg
Hide files with File Manager
Even though this is not actually an encryption process, it is quite helpful for hiding important data in plain sight.
Thus, you can open your distributions default file manager in the location you are planning to hide a file. Right-click an empty spot and select New Folder. Name the folder starting with a period (i.e if you plan to name it data
, you should type .data
).