Table of Contents
#Introduction
In this tutorial, How to Password Protect Files on Linux. To prevent unauthorized access to files and folders and secure them with a strong password.
To password protect files on Linux, you have multiple options. Here are a few methods you can use
How to Password Protect Files on Linux
Encrypt a File with GnuPG
I use gpg command to encrypt a file. GnuPG is a free Linux program that supports multiple encryptions for file encryption.
1. Open the terminal
2. Run the following command line to encrypt your file.
gpg -c your_file
GnuPG will create an encrypted file with .gpg extension in your current working folder.
The result is the picture below:

To access it, you’ll need to decrypt it. For this, run the following command
gpg your_file.gpg
The result is the picture below:

other encryption algorithms, first, check the supported ones by running:

For example, you specify the desired algorithm as a command below
gpg -c --cipher-algo algorithm_name your_file
using the zip command to Encrypt a File
the zip command is another CLI utility that password-protect files on Linux. it is pre-installed on all Linux distros.
zip --password your_password archive_file.zip file1 file2
you replace your_passowrd with the password you want to use to encrypt the archive.
Unzip the archive and enter your password. you can run the command below:
unzip archive_file.zip
Encrypt a File Using mcrypt
list out all the supported encryption algorithms
mcrypt --list
encrypt filename
mcrypt -a algorithm_name filename
If you wish to open this file, you’ll need to decrypt it as the command below:
mcrypt -d filename.nc
Conclusion
You have Password Protect Files on Linux. Remember to choose a strong password when prompted, and consider using a password manager to securely store your passwords. I hope will this your helpful. Thank you for reading the DevopsRoles page!