How to Password Protect Files and Folders in Linux

Whether you share your files online, store them in the cloud, store them on a thumb drive, or add them to an archive, password protecting your files protects their contents and prevents unauthorized access. is the best way to

The same applies to folders. So it’s important to encrypt those too. There are several ways to password protect files and folders in Linux. Most of these methods use encryption and provide better protection than others.

Here, we’ll take a look at all the different methods you can use to password protect your files and folders in Linux.

How to Password Protect Files in Linux

Linux has multiple utilities that help you password protect/encrypt files on your computer. Below are the methods you can use to do this.

Method 1: Encrypt files using GnuPG

GnuPG is a free Linux program that supports multiple encryption standards for file encryption. It comes pre-installed on most Linux distributions and is very easy to use.

GnuPG is accessible via the CLI. Here’s how to use it to encrypt your files:

  1. Open a terminal.
  2. Use the cd and ls commands to navigate to the directory containing the files you want to password protect.
  3. Once in the directory, run the following command to encrypt the files:
    gpg -c filename
  4. Finally, when prompted for a passphrase, enter a strong, easy-to-remember passphrase.

GnuPG now creates encrypted files ( .gpg extension) in the current working directory. To access it, you need to decrypt it.To do this, run the following command and when prompted for the password enter the one you used to encrypt the file and hit come in:

See also  Tales of Come up Ufotable animation revealed alongside the new Gallery application

gpg filename.gpg

GnuPG will return the decrypted version of the file in the current working directory.

If you want to use other encryption algorithms, first check the supported algorithms by running the following command:


Then specify the desired algorithm in the command as follows:

gpg -c 

Method 2: Encrypt files using Zip

Zip is another CLI utility that can password protect files in Linux. It comes pre-installed on all major Linux distributions and is perfect for archiving or compressing multiple files into a single encrypted archive.

To password protect files using Zip, follow these steps:

  1. open a terminal and CDs When ls A command to navigate to the directory containing the files to be encrypted.
  2. Create a password-protected zip file by entering a command in the following format:
    zip --password preferred_password filename1 filename2

    where the exchange preferred_password password used to encrypt the archive and Give the file name you want to give the resulting archive.

To access these files, unzip the archive and enter the password. Or to run it via terminal, run:


Zip will ask for your password.Enter the password set at the time of encryption and hit come in Decrypt the file.

Method 3: Encrypt files using mcrypt

mcrypt is a crypt replacement that facilitates file encryption on Linux. It supports various encryption standards and gives you the option to specify encryption algorithms based on your preferences.

Here are the steps to encrypt a file using mcrypt:

  1. Open a terminal and use cd and ls to navigate to the directory containing the files you want to encrypt.
  2. Enter the following command to list all supported encryption algorithms.
    mcrypt --list
  3. Finally, encrypt the file using:
    mcrypt -a algorithm_name filename

    You will be asked for a passphrase, enter it twice come in.

mcrypt encrypts the file and saves it with a “.nc” extension. To open this file, you need to decrypt it. To do this, run:

mcrypt -d

Then enter your decryption passphrase.

How to password protect a folder in Linux

Similar to how to password protect files in Linux, password protecting folders is easy. Below is a list of all the methods available and the steps to use them.

Method 1: Encrypt Folders Using GNOME EncFS Manager

GNOME EncFS Manager is a mounting utility that makes it easy to encrypt folders on Linux. It is supported by most Linux distributions and has an easy-to-use GUI.

Here are the steps to use GNOME EncFS Manager to encrypt folders on Linux:

  1. Open the application menu, GNOME EncF and launch it.
  2. Plus (+) icon in the toolbar. In the next dialog box, select the second radio button below. Directory or drive to encrypt or import Select a folder. Make sure to create a new (empty) folder here. (You will need to move the contents of the original folder to this folder later.)
  3. Select the appropriate option for Mount Directory, i.e. where you want to mount the encrypted folder.
  4. under passwordenter the password used to encrypt the folder twice.
  5. strike create Create an encrypted folder.

GNOME EncFS Manager creates an encrypted folder (also called stash) and mounts it to the selected destination directory. Double-click this mounted drive to access the contents of the folder inside. To unmount, clear the check box next to it.Or right click on the stash and select unmount.

If you want to mount it again, check the checkbox. GNOME EncFS Manager will ask for your password. After entering the password, you will be able to access all its content.

Method 2: Encrypt folders using VeraCrypt

VeraCrypt is a free and open source disk encryption tool. Available for all major operating systems, it can be used to create encrypted directories in Linux where files and folders can be stored securely.

First, download and install VeraCrypt on your computer from the link below.

download: Veracrypt

Then launch it from the application menu and follow these steps:

  1. Select a drive slot and click . create volume.
  2. select Create an encrypted file container and hit Next.
  3. Select volume type standard veracrypt.
  4. click choose a file Create a file to store the encrypted disk.
  5. Select the encryption algorithm and hash algorithm according to your preference and hit. Next.
  6. Specifies the volume size for this drive.
  7. Enter your password to lock this drive twice, Next.
  8. Select the volume format type, i.e. file system, from the dropdown.
  9. Finally, hit format Create a VeraCrypt volume.

Now we need to mount this encrypted volume. To do this, go back to VeraCrypt’s main window and type Select files under volume. Select a file and click mount. When prompted for a password, enter the password you set when you created the volume.

VeraCrypt mounts the encrypted drive. Then you can add all your personal data (files or folders) to this drive. When you’re done working with these files and want to lock them and hide them, unmount the drive.

Effectively protect personal data on Linux

According to your preference, you can choose the above methods and tools to password protect files and folders on Linux to prevent unauthorized access. If you share your computer with someone, this is a very effective way to ensure that no one can access your personal data except you.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.