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
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 DirThis 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/qwertyor
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 newpasswordThis method has quite a few issues.
- After gaining access the password will be clearly visible for all to see in the terminal prompt or nautilus address bar.
- Scripts inside
Dirwhich depend on their exact location in the filesystem won't work properly. - 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.
4You are probably looking for gpgdir from the packet signing-party (standard ubuntu repository) which can encrypt directries recursively.
The manual page is here:
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).