Thursday, February 03, 2011

How do you prevent other linux users from listing your files in a directory?

I'd got this question from Ahmet from Turkey via Aardvark. I'd known this answer for a while and it was trivial to reply. For posterity, here's my answer:


The short and sweet answer:

1) Use the chmod tool to remove the "others read/write/execute" permission bits from the directories that you don't want others to be viewing. A command like 


   chmod 750 /path/to/directory/root 

should do the trick. You might even want to consider the -R option for recursive application of these permissions.

Note: if you don't use the recursive option, you might be able to ls or cd into a subdirectory even if the parent directory has the permissions disabled.


2) For an explanation of why this works, just have a look at this site: http://www.perlfect.com/articles/chmod.shtml - the directory permissions section should make things clear.

A short synopsis is:
Read permission on a directory - Allows ls to list the files in the directory
Write permission on a directory - Allows files to be deleted
Execute permission on a directory - Allows a user to cd into the directory

Technically:
Read - Read the directory inode and hence list the files and related info
Write - Modify the directory inode
Execute - Allow a chdir(...) system call to succeed on the particular inode

Removing these permissions is akin to saying that you don't want anybody else messing around with this inode (that you own).
If you want to know more about inodes, check out Inodes on Wikipedia.

10 comments:

  1. Very Good website. I like the contents. From www.amourfleurs.com/France_Valentineday.asp

    ReplyDelete
  2. Keep up the good work. Best of luck. From www.singaporeflowershop.com

    ReplyDelete
  3. Website is very comprehensive and informative. I have enjoyed the visit. From www.indiaonlineflorists.com

    ReplyDelete
  4. The visit was useful. Content was really very informative. From www.expressflowersindia.com

    ReplyDelete
  5. Keep up the good work. Best of luck. From www.expressgiftsindia.com

    ReplyDelete
  6. Very Good website. I like the contents. From www.gifts-to-india.com

    ReplyDelete
  7. The visit was useful. Content was really very informative. From www.rightflorist.in

    ReplyDelete
  8. Website is very comprehensive and informative. I have enjoyed the stay. From www.expresscakesindia.com

    ReplyDelete
  9. visit was useful and informative.

    ReplyDelete
  10. Great to see your blog. It is really very interesting. Send Gifts & Flowers to India please visit.
    Send Gifts to India

    ReplyDelete