$ touch testfile
$ chmod g+w testfile
$ sudo adduser user2 user1
$ stat -c'%a %A' testfile
664 -rw-rw-r--
$ su user2
Password:
$ groups
user2 user1
$ rm testfile
rm: cannot remove `testfile': Permission denied
What is missing?
What is missing? |
||||
|
|
|
Deleting a file means you are making changes to the directory it resides in, not the file itself. Your group needs rw on the directory to be able to remove a file. The permissions on a file are only for making changes to the file itself. This might come off as confusing at first until you think about how the filesystem works. A file is just an inode, and the directory refers to the inode. By removing it, you're just removing a reference to that file's inode in the directory. So you're changing the directory, not the file. You could have a hard link to that file in another directory, and you'd still be able to remove it from the first directory without actually changing the file itself, it would still exist in the other directory. |
|||||||||||||||||||
|
|
Only the system can delete a file, and only if it has no references. A mere user can only unlink a file, that is, remove it from a directory. You need write access to a directory to unlink a file from it. Unlinking a file doesn't modify the file, so write access to the file is irrelevant. |
|||
|
|