How To Password Protect A Folder In Linux

In the last post, we saw how to create password protected zip file in Linux. In this post, we’ll see how to password protect a folder in Ubuntu Linux.

You might be in a situation when you often share your computer with other people but you have some private files that you don’t want others to see.

You can obviously hide it at places where others cannot find it. But that’s not entire foolproof because the files will be shown in the desktop search results.

I remember that when I was in college, popular ways to hide ‘special files’ were to put it under the C drive or in a deeply nested folder structure. There were also some applications that used to lock the folders with a password. Like gallery lock applications on smartphones, these applications were vastly popular for hiding private files etc.

I haven’t used such folder locking applications in Linux for years. Mostly because my laptop is used only with me and also because I do not have the need to hide any files.

If so, then why are we talking about folder lock for Linux today? It’s because I got a request from an It’s FOSS reader for a tutorial on encrypted folders in Ubuntu. If this is something that interests you, let’s see how to lock a folder in Linux.

How to password protect folders in Linux

Password protect folders in Linux

Before you go on with the instructions let me warn you about something. The tools mentioned here uses EncFs. It is an open source cryptographic file system.

The problem with EncFs is that a security audit in 2014 found some vulnerabilities in EncFs. Though these vulnerabilities are not easily exploitable, it means that EncFs is not ‘military grade’ secure. For an average desktop user, it should work just fine.

I am using Ubuntu in this tutorial but you can any other Linux distribution based on Ubuntu such as Linux Mint, elementary OS etc. In fact, the steps should be applicable to other Linux distributions such as Fedora, Arch Linux etc but the commands to install the tool won’t be the same.

Method 1: Lock folders with Gnome Encfs Manager

Let’s see how to install Gnome Encfs Manager.

If you are using Ubuntu or Linux Mint or other Linux distributions based on Ubuntu, you can use the official PPA using the commands below one by one:

sudo add-apt-repository ppa:gencfsm 
sudo apt update 
sudo apt install gnome-encfs-manager

Packages for Debian, Fedora and openSUSE are available here.

If you are using GNOME on Wayland (for example Ubuntu 17.10), you should use this GNOME extension to add the quick access to the top panel. Read this article to learn how to use GNOME extensions.

Once installed, you may have to log out to see the application working. Go to the application menu and start Gnome Encfs Manager. Click on the + sign to add a new folder that you’ll be locking with a password. A password protected folder is called stash in this application’s terminology.

Gnome Encfs manager

In here, you can create a new directory or browse to an existing one. You can try to password protect an existing folder but the files that are already present in the folder won’t be locked. For this reason, I suggest creating a new folder and move the files after you password protect it.

Don’t forget to use a password that you will remember easily. If you forget the password, you should also forget the files locked with it.

Locking a folder in Linux

Once you have the folder created, you can start copying the files to it. Your locked folder will be seen a mounted drive when you have unlocked it.

Lock a folder in Ubuntu Linux

You can get the control on the locked folder from the GNOME extension. I am not sure if other desktop environments have anything similar. I leave that to your exploration.

Control locked folder with Gnome Encfs Manager

Once you have copied the files in the secret folder, simply unmount it. You can do that by unchecking the mounted folder from the panel extension as shown above. When you want to access it, use the launcher in top panel or start the program again.

You can also use some advanced settings such as auto-start or auto unmount after certain idle time.

Password protect a folder with Gnome Encfs Manager

Note that the so-called secret directory will be visible and accessible to anyone in its normal location. However, its content won’t be in the readable format, not even the filenames. When you mount the locked folder, it will become readable.

That’s all you need to know about password protecting folders with Gnome Encfs Manager.

Related post: How to change user passwords in Ubuntu-based Linux distributions.

Method 2: Lock files with Cryptkeeper

Another warning here. Cryptkeeper has a vulnerability with the newer versions of EncFs (1.9 and above). The vulnerability has not been fixed and it is less likely that it will ever be fixed because the project has been abandoned. There is no new change in the code for past several years and the developer’s website doesn’t exits anymore.

That’s the reason why I won’t recommend using this method anymore.

Cryptkeeper is a GUI tool that uses EncFS in the background. It is a popular application and is available in most of the software repositories by default.

For Ubuntu and other Ubuntu based Linux distributions, use the command below to install Cryptkeeper.

sudo apt-get install cryptkeeper

For Fedora based Linux distributions, use the command below:

sudo yum install cryptkeeper

Once installed, I suggest a restart to avoid surprises. You can start the program straight away as well.

Cryptkeeper in Ubuntu
Cryptkeeper in Ubuntu Unity

Once you start Cryptkeeper, you won’t see the interface immediately. You’ll have to look into the top panel (or the bottom panel, depending upon the desktop environment). Cryptkeeper is an indicator applet rather than a full-fledged desktop application.

Click on New encrypted folder to create a new secret folder.

Create new encrypted folder in Ubuntu
Click on New encrypted folder

Name the folder and select its location. And then click on Forward.

Name the encrypted folder and select its location
Name the folder and select its location

You’ll have to provide a password for the encrypted folder. After that, click on Forward.

Password lock the folder in Ubuntu
Provide a password

Voila! Your password protected folder is read to use.

Password protected folder successfully created
Password protected folder successfully created

To access the locked folder, you’ll have to select it from Cryptkeeper indicator applet:

Access encrypted folder
Access encrypted folder

Of course, it will ask for the password:

Enter the password for locked folder
Enter the password

Once you do that, your secret folder will be accessible to you. You can see it mounted as a separate partition. It’s because EncFS creates a separate filesystem inside user-space.

You can create new files in the encrypted folder or copy paste items from other directories to it. Once you have unlocked it, you can use it as a normal folder.

Locked folder in access
Locked folder in access

To lock the folder again, you’ll have to use the indicator applet again. Go to it and de-select the required folder i.e. simply click on it again.

Lock the folder again with Cryptkeeper
Lock the folder again

If you want to permanently delete the secret folder, you can choose the Edit option from the Cryptkeeper menu. Same Edit menu also gives you the option to change password.

Change password or delete locked folder
Change password or delete folder

Note that, Cryptkeeper won’t be started automatically at each boot. If you want that, read this guide to manage start up applications in Ubuntu and see how can you start Cryptkeeper at each boot.

Enjoy your private locked folder in Linux :) Any questions or suggestions are always welcomed.

Similar Posts

  • E: Unable to locate package cryptkeeper
    it shows this when i try to intstll cryptkeeper , the case is same with first cryptkeeper not working in 2022 or what ?