Is there any way to lock a folder from terminal(protected with password) without using any third party applications like truecrypt,crypteeper nor giving user permissions.

It was just like whenever a user try to open that folder,it suddenly prompt for password.The given password must not be similar to sudo password.

4 Answers 4


May be too naive but how about the following:

Let Dir be the directory to be password protected with password qwerty.

mv -n Dir qwerty
mkdir Dir
mv qwerty Dir/.
chmod a-r Dir

This just creates a folder called querty inside Dir with the contents of Dir and removes read permissions to Dir.

To access from terminal:

cd Dir/qwerty


cd Dir/
cd qwerty/

Note that pressing tab or typing ls won't reveal qwerty. In other words you need to know qwerty to reach the original contents of Dir.

To access from nautilus:

Navigate to Dir. Press Ctrl+L. Type qwerty in the location bar to enter.

Changing password:

cd Dir
mv qwerty newpassword

This method has quite a few issues.

  1. After gaining access the password will be clearly visible for all to see in the terminal prompt or nautilus address bar.
  2. Scripts inside Dir which depend on their exact location in the filesystem won't work properly.
  3. Most importantly, sys-admins will be able to access contents without the password - this may not be desirable.

Apart from these there could be other security flaws: this was never intended to be an encryption scheme. That said, from the sound of the question, I guess this might be sufficient.


The classic sg(1) utility may do what you want, even if the interface hasn't changed for decades, and is just a little more complicaded than what you asked for. what you do is create a special group with no users and a password (see group(5) and gshadow(5) for details), then you change the group of the folder to this new group and set the permissions for the folder to allow access by the group ( either 0770 or 0750 ) so that when your guest tries to cd into the folder, you get access denied. now you use sg to change your group to this new group you can now cd into the directory until you type exit to return to your previous permissions.

Providing access to gui applications presents additional challenges, because sg was written long before X11.

  • it was not just like giving permissions to the user. Nov 19, 2013 at 17:12
  • @AvinashRaj you don't give permissions to the user, you give permissions to the group, and since the user is not a member of the group, they have no permission. When they run sg, it asks for the group password, which if entered correctly, lets the user temporarily join the group.
    – hildred
    Nov 19, 2013 at 17:17
  • its not about permissions,when you try to open that folder it asks for password. Nov 19, 2013 at 17:22
  • @AvinashRaj So you are not trying to add a restriction, but remove one? to solve this what are the permissions of the folder returned by ls -l What is the command you are using to open the folder, and how does it respond, and what does file say your folder is?
    – hildred
    Nov 19, 2013 at 22:47

You are probably looking for gpgdir from the packet signing-party (standard ubuntu repository) which can encrypt directries recursively.

The manual page is here: http://manpages.ubuntu.com/manpages/saucy/man1/gpgdir.1.html


I am suprised nobody mentioned this solution with zip command, it doesn't requires any 3rd party package.

zip -er Folder.zip Folder

This will encrypt your folder and will require the password everytime to open each file.

However this wont hide the filename(s), but if you need stronger protection to filename then go for 7zip but thats not bundled in linux version particularly ubuntu or its variant(s).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .