How to password protect files and folders on Linux

Whether you want to share a file online, store it in the cloud, upload it to a thumb drive, or add it to your archive, password protection is the best way to secure its content and prevent unauthorized access.

The same goes for folders as well. Therefore, it is necessary to encrypt it as well. In Linux, you have several ways to password protect files and folders. Most of these methods use encryption, which provides more additional protection than others.

Here’s a look at all the different methods you can use to password protect files and folders on Linux.

How to password protect files on Linux

Linux has multiple utilities to help you protect/encrypt files on your computer with a password. Listed below are the methods you can use to do this.

Method 1: Encrypt a file with GnuPG

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

GnuPG can be accessed via the CLI. Here’s how to use it to encrypt a file:

  1. Open the station.
  2. Use the cd command and the ls command to navigate to the directory containing the file you want to password protect.
  3. Once in the directory, run the following command to encrypt your file:
    gpg -c filename
  4. Finally, when asked to enter a passphrase, type one that is strong and easy to remember.

GnuPG will now create an encrypted file (with the extension .). .gpg extension) in your current working directory. To access it, you will need to decrypt it. For this, run the following command, and when you are asked for a password, enter the word you used to encrypt the file and press Enters:

gpg filename.gpg

GnuPG will return an encrypted copy of the file in the current working directory.

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


Then specify the desired algorithm in the command as follows:

gpg -c 

Method 2: Encrypt a file with Zip

Zip is another CLI utility that allows you to password protect files on Linux. It comes pre-installed on all major Linux distributions and is ideal for archiving or compressing multiple files into one encrypted archive.

Follow these steps to use Zip to password protect a file:

  1. Open the device and use the file CD And the ls Commands to go to the directory with the files to be encrypted.
  2. Enter the command in the following format to create a password-protected zip file:
    zip --password preferred_password filename1 filename2

    Here, replace favorite password with the password you want to use to encrypt the archive and With the name of the file you want to give to the output archive.

Now, when you want to access these files, unzip the archive and enter your password. Or to do this across the terminal, run:


Zip will now ask you for a password. Enter the password you set at the time of encryption and press Enters To decrypt the file.

Method 3: Encrypt a file with mcrypt

mcrypt is an encryption alternative that makes file encryption on Linux easy. It supports different encryption standards and you have the option to select the encryption algorithm based on your preference.

Here are the steps to encrypt a file with mcrypt:

  1. Open Terminal, and using cd and ls, navigate to the directory containing the file you want to encrypt.
  2. Enter the command below to list all supported encryption algorithms:
    mcrypt --list

  3. Finally, encrypt your file with:
    mcrypt -a algorithm_name filename

    When prompted for a passphrase, enter it twice and press Enters.

mcrypt will now encrypt your file and save it with a “.nc” extension. If you want to open this file, you will need to decrypt it. To do this, run:

mcrypt -d

Then enter the decryption passphrase.

How to password protect folders on Linux

Similar to how you password-protect files on Linux, password-protecting folders comes in handy as well. Here is a list of all the methods you can use and the steps to use them.

Method 1: Encrypt a folder with GNOME EncFS Manager

GNOME EncFS Manager is an installation utility that allows you to easily encrypt folders on Linux. It is supported by most Linux distributions and has a neat graphical user interface, which makes it easy to use.

Here are the steps for using GNOME EncFS Manager to encrypt a folder on Linux:

  1. Open the application list, search for nexus gnome and release it.
  2. Press the plus sign (+) in the toolbar. In the next dialog, select the second radio button under Manual or drive to encode or import and 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 a suitable option for the download directory, i.e. the location where you want to install the encrypted folder.

  4. under passwordEnter the password you want to use to encrypt the folder twice.
  5. He hits Create To create an encrypted folder.

GNOME EncFS Manager will now create an encrypted folder (also called stash) and install it to the specified destination directory. Double-click this mounted drive to access the contents of the folder inside it. To unmount it, check the checkbox next to it. Or right-click on the cache and select Uninstall.

Now, when you want to install it again, just select the check box. GNOME EncFS Manager will ask you for your password. Enter the password, and you will now be able to access all of its contents.

Method 2: Encrypt a folder with VeraCrypt

VeraCrypt is a free and open source disk encryption tool. It’s available on all major operating systems, and you can use it to create an encrypted directory on Linux where you can securely store files and folders.

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

Download: IraCrypt

Next, launch it from the list of applications and follow these instructions:

  1. Select the drive slot and click Create a volume.

  2. Choose Create an encrypted file container and hit next one.

  3. Choose size type like iCrypt standard.

  4. Click select file And create a file to store the encrypted disk.
  5. Select an encryption algorithm and a hash algorithm as per your preference and tap on it next one.

  6. Give a volume size for this drive.
  7. Enter a password to lock this drive twice and press next one.
  8. Choose the folder format type i.e. file system from the dropdown list.

  9. Finally, hit appearance To create a VeraCrypt folder.

Now, you need to download this encrypted folder. To do this, go back to the main VeraCrypt window and click Select a file under Volume. Choose the file and click multiple. When prompted for a password, enter the password you set at the time the volume was created.

VeraCrypt will now install the encrypted drive, and after that, you can add all your personal data (files or folders) to that drive. When you’re done working with these files and want to lock and hide them away, unmount the drive.

Effectively Securing Personal Data on Linux

Depending on your preference, you can choose any method and tool listed above to password protect your files and folders on Linux and prevent unauthorized access. If you share your computer with someone, this can be a really effective way to ensure that no one but you can access your personal data.

(Visited 1 times, 1 visits today)

Related posts

Leave a Comment