If I have two users called john and sally. Both are part of the users group. john creates a directory with permissions 775. sally then puts a file there with 644 permissions.

Even though the file obviously has no group write privileges. Can john then modify/delete that file in the directory he owns but the file he does not own?

  • 1
    I have problem with your subject: "Directory permissions vs file permssions", Directory is a file too in UNIX world. but regural file differ. – PersianGulf Oct 10 '13 at 14:43

He can delete the file because unlinking depends on the directory's permissions, not the files. In this way, he can modify it since he can remove and replace it in the directory.

| improve this answer | |
  • So the file would then be owned by john? When you say modify would that be a standard by applications (such as vi) to read, remove, and/or replace the file with the new one? Would that work in the same way as moving the file? – Gareth Oct 10 '13 at 13:19
  • Yes, vi would support replacing the file with :w!. – jordanm Oct 10 '13 at 13:24
  • And moving the file? – Gareth Oct 10 '13 at 13:28
  • @gareth The same as deleting it. Moving it just changes the source and destiantion directories. – kurtm Oct 10 '13 at 14:37

Yes, deleting a file doesn't actually modify the file, it modifies the directory and john has permission to do so.

The way to prevent this behavior is to set the sticky bit on the directory. That is how /tmp allows everyone to write to it, but only the owners (or root) to delete things from it.

chmod +t directory

That will turn the sticky bit on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.