I have a file with the following permissions:

root:data, and chmod set to 775.

My normal user, let's call him boby, is in the data group.

Why can't I delete the file with the user boby?

 rwxrwxr-x 18 root data 4096 2011-12-30 22:02 storage
 my user is in the group data but can't write into storage
link|improve this question

25% accept rate
feedback

3 Answers

Because deleting a file you are not just modifying the file but also modifying the directory.

So if your file is:

rwxrwxr-x

You would be able to do:

cp /dev/null <filename>

But if your directory permissions are:

rwxr-xr-x  root  data  <directory name>

Then system will prevent you removing the file.

link|improve this answer
I have drwxrwxr-x on the directory, I think it has something to do with the d in front – user56301 Dec 30 '11 at 19:55
1  
@user56301 d just indicates that this file is a directory. What's the ownership of the directory? – Karlson Dec 30 '11 at 19:58
drwxrwxr-x 18 root data – user56301 Dec 30 '11 at 19:59
Try running as user boby the following: cd <directory> ; touch test_file ; rm test_file – Karlson Dec 30 '11 at 20:02
@user56301 can you create a file in that directory? if you can not, then you definitely can't delete a file there. – Rich Homolka Dec 30 '11 at 20:03
show 1 more comment
feedback

File deletion is based on directory perms, not file perms (*).

Do you have write permissions on the directory that contains the file?

(*) Caveat, you can have a directory where you enforce that only the owner of the file can delete it. This is useful for temp dirs.

link|improve this answer
feedback

If the containing directory does not permit the user boby or the data group to write to it, then that would explain this behavior.

link|improve this answer
So the entire path needs group permission? It works like that. – user56301 Dec 30 '11 at 20:06
@user: Not the entire path - just the file's immediate parent directory. You are only modifying the directory's contents. The higher parents do not matter at all. – grawity Dec 30 '11 at 20:08
I update the answers – user56301 Dec 30 '11 at 20:09
This is not exactly true. You only need write perms on the containing directory. The perms can be any of user, group, or other, it doesn't have to be group perms that allow you. – Rich Homolka Dec 30 '11 at 20:12
@Rich: AFAIK, only one set is checked. If you are the owner, the system will only check 'owner' perms, not 'group' nor 'others'. If you are in the group, the system won't check 'others' perms. (touch foo; chmod 6 foo; ls -l foo; cat foo) – grawity Dec 30 '11 at 20:24
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

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