Skip to content

How to password protect Folders and Files in Linux

Password protect Folders and Files in Linux

Whether you’re storing your file in the cloud, sharing it online, keeping it in a thumb drive, or adding it to your archive, it’s important to always password protect folders and files from unauthorized access and also secure the content. 

This is why it’s important to encrypt them as well. There are different ways to password-protect files and folders on Linux. Many of these methods use encryption, which gives additional protection than others.

Let’s take a look at all several methods you can use to password-protect your files and folders on Linux.


How do I password protect a file in Linux?

Linux has many utilities that allow you to encrypt or password-protect files on your computer. The methods you can use to do this are listed below:

Encrypt a File With GnuPG

GnuPG is a free Linux program that allows multiple encryption standards for file encryption. It is usually pre-installed on most Linux distros and is pretty simple to use.

You can access GnuPG via the CLI. Here’s how you can use it to encrypt a file :

  • Open the terminal.
  • Go to the directory containing the file you want to password-protect by using the cd command and ls command.
  • When you’re inside the directory, run the following command to encrypt your file:
  • gpg -c filename
  • Finally, when prompted for a passphrase, type in a strong one that’s also easy to remember.

Then, GnuPG will create an encrypted file (with .gpg extension) in your current working directory. You’ll need to decrypt it before you can access it. 

To do this, run the following command, and when prompted for a password, type in the one you used to encrypt the file and click on Enter:

gpg filename.gpg

A decrypted version of the file will be returned by GnuPG into your current working directory.

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

gpg –version

Then, specify the desired algorithm in the command like this:

gpg -c –cipher-algo algorithm_name filename

Encrypt a File By zipping

Zip is another CLI utility that allows you to password-protect files on Linux. It comes pre-installed on all notable Linux distros and is perfect for zipping multiple files into one encrypted archive and archiving them as well.

Simply follow these steps to use Zip for password-protecting a file:

  • Open the terminal and use the cd and ls commands to navigate to the directory with the files to encrypt.
  • Input the command in the following format to create a password-protected zip file:
  • zip –password preferred_password filename1 filename2
  • Then, replace preferred_password with the password you’d like to use to encrypt the archive and with the file name you want to give to the resultant archive.

Now, you must unzip the archive when you want to access these files and type in your password. Otherwise, to do it via the terminal, run:


The zip will ask you for a password. Type in the password you set at the time of encryption and click on Enter to decrypt the file.

Encrypt a File With mcrypt

mcrypt is a crypt replacement that makes it easier to encrypt files on Linux. It supports different encryption standards and it gives you the option to specify the encryption algorithm based on your preference.

Here’s how to encrypt a file using mcrypt:

  • Open the terminal, and using cd and ls, go into the directory that contains the file you want to encrypt.
  • Enter the command below to list out all the supported encryption algorithms:
  • mcrypt –list
  • Finally, encrypt your file using:
  • mcrypt -a algorithm_name filename
  • When asked for a passphrase, enter it twice and hit Enter.

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

mcrypt -d

Then, type in the decryption passphrase.

How to Password-Protect Folders on Linux

Password-protecting a folder is straightforward and quite similar to how you password-protect files on Linux. Here’s a list of all the methods you can use and the steps to use them.

Encrypt a Folder Using GNOME EncFS Manager

GNOME EncFS Manager is a mounting utility that allows you to encrypt folders on Linux easily. Most Linux distros support it and it has a neat GUI, which makes it easy to use.

Here’s how to use GNOME EncFS Manager to encrypt a folder on Linux:

Open the applications menu, search for GNOME EncFs and launch it.

Click on the plus (+) icon in the toolbar. Then, from the dialog box that follows, select the second radio button below Directory or drive to encrypt or import and select a folder. 

You have to create a new (empty) folder here. (You’ll later need to move the contents of your original folder to this folder)

Choose an appropriate option for the mount directory. This is the location where your encrypted folder will be mounted.

Under Password, type in the password you’d like to use to encrypt the folder twice.

Click in Create to create an encrypted folder.

GNOME EncFS Manager will now create an encrypted folder (also referred to as stash) and mount it to your selected destination directory. 

Double-checking on this mounted drive will give you access to the contents inside the folder. When you want to unmount it, check off the checkbox beside it. Otherwise, simply right-click on the stash and select Unmount.

When you want to mount it again, just mark the checkbox. GNOME EncFS Manager is going to ask you for your password. Type in the password, and you’ll be given access to all its contents.

Encrypt a Folder with VeraCrypt

VeraCrypt is an open-source and free disk encryption tool. You can find it on all major operating systems, and use it to create an encrypted directory on Linux where you can save files and folders securely.

To begin with, download VeraCrypt on your computer through the link below and install it.

Download: VeraCrypt

Then navigate to your applications menu, launch it, and follow these instructions:

  • Choose a drive slot and hit Create Volume.
  • Select Create an encrypted file container and click on Next.
  • Select volume type as Standard VeraCrypt.
  • Click on Select File and create a file to save the encrypted disk.
  • Choose an encryption algorithm and hash algorithm according to your preference and click on Next.
  • Select volume format type, i.e., file system from the dropdown.
  • Finally, click Format to create a VeraCrypt volume.

Now, you have to mount this encrypted volume. To do this, simply go back to the VeraCrypt main window and click on Select File under Volume. 

Select the file and click on Mount. When prompted for a password, type in the password you set during the time of volume creation.

Then, VeraCrypt will mount your encrypted drive, and afterward, you can add all your data (folders or files) to this drive. 

When you’re done working with these files and want to lock and hide them away, just unmount the drive.


Securing data on Linux

Considering your preference, you can choose any method and tool listed above whenever you want to password-protect your files and folders on Linux to prevent unauthorized access. 

It is important for those who do share their computer with other people, to make sure nobody besides them can access their data.

Leave a Reply

Your email address will not be published.