I would like to ask what are the rules that Linux OS's are using on ext4 file systems when there are conflicts between directory permission and file permissions.


 drwxrwx--- user1 group2 FOLDER
 -rw-r--r-- user1 group1 FILE

What permissions a user in a group2 on a file FILE would have?...And what is the general rule for determining file permissions in this situations?



If a user is in group2, then they'd follow the group permissions for the directory FOLDER. i.e.


Presuming that they are not user1 and also not in group1, then we'd look at the "other" permissions for FILE. i.e.


Hence, they only have read permissions for this file. Note that this is a bit confusing. They cannot directly modify this file, since don't have write privileges. However, since they have wx for the directory, they could rm this file, then replace it with a new one. (N.B. the inode would probably change, and they wouldn't be able to chown it to the original owner, so it's not exactly the same as directly modifying the file.)

So in general, the permissions inherit from the most-parent directory. As permissions get more restrictive, they restrict the children files and directories. However, as above, if you have wx permissions to the top-level directory, there are workarounds.


Similarly, if you edit the file with vim, then you'll see a change in inode. It's not "editing" it, but "over-writing" it.

$ echo foo > file
$ ls -li file 
5213942 -rw-r--r-- 1 sparhawk sparhawk 4 Aug 16 15:34 file
$ sudo chown root:root file
$ ls -li file 
5213942 -rw-r--r-- 1 root root 4 Aug 16 15:34 file
$ vim file
$ ls -li file 
5214750 -rw-r--r-- 1 lee lee 7 Aug 16 15:35 file

Note the change in inode after vim overwrites the file. Also note that vim gave a warning that the file was readonly. I had to save with :w!.

  • Actually , that was my real question. Is there any general rule, like following the rule of the lowest permission or something like that, like in Windows? – majestik33 Aug 16 '14 at 5:12
  • In fact, I tried to change the content of the mentioned file in Fedora 18 in this set up and it did let me do it. But when the next time I run the command ls -l it showed this output – majestik33 Aug 16 '14 at 5:17
  • Sort of. However, you really have to traverse the entire directory to tell. For example, if you have two directories, a -wx parent and +wx child, you cannot write in the parent, but can in the child. Start at the top-most directory, and read down. If you encounter a -x, then you can't progress any more. If you encounter a -w, then you might be able to. – Sparhawk Aug 16 '14 at 5:18
  • -rw-r--r-- user group2 FILE – majestik33 Aug 16 '14 at 5:18
  • I'm not sure I understand. Did the user change from user to user1, and group change too? What is your username? Also, how did you "change the content"? – Sparhawk Aug 16 '14 at 5:20

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.