How to Lock Folders/Directories in Linux

Whenever I go to home on vacations, I usually share a lot of Music/Videos with my friends. On many occasions, my laptop is being used by someone else and since its a personal notebook, there is a lot of stuff I don't want people to mess around with. Under such cases, restricting other users by locking stuff comes in handy.

Since, most of my hometown friends are neither really techie nor even Linux users, a simple change in file permissions does the trick.

Lets say, I want to restrict some personal stuff in a folder named "special". Since, the system is being accessed from my account, probably the safest way would be to shift the creator/user rights of the folder to some other user for a while, preferably root. It can be easily done with this command.

[root]# chown -R root:root special/

Coauthor, Chia, wrote a good howto on linux file ownerships, check it out if you are unaware of the basics.

So, now the ownership of the folder is changed to root, but other users might still be able to access/read the files. If you want to restrict even opening of the directory i.e. completely locking it, then just change the permissions of the folder for other users. This can be done using the following command.

[root]# chmod -R 700 special/

A person on board can still change the whole thing back if he even knows your account's password. That is in case of Ubuntu, since the whole setup can be done as well as reversed using sudo. But this method pretty much does the job.

1 Comment

Anon Linuxer (not verified)
August 21st, 2010 06:18 pm
but you forgot to say how to get the folders back to their original status... ;) a noob linuxer like me would be lost... :P

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.