$ 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?
$ 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?
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.
It seems like in order to delete files from the directory you need user write permissions. Group write and all write are not enough, despite what the accepted answer says.
I tested this on two machines on two filesystems:
$ mkdir testdir
$ touch testdir/foo
$ chmod u-w testdir
$ chmod o+w testdir
$ ls -ld testdir
dr-xr-xrwx 2 tim all 17 Nov 25 23:08 testdir
$ rm testdir/foo
rm: cannot remove 'testdir/foo': Permission denied
$ chmod g+w testdir
$ rm testdir/foo
rm: cannot remove 'testdir/foo': Permission denied
$ chmod u+w testdir
$ rm testdir/foo
775 drwxrwxr-x
for the directory. – tshepang Feb 15 '11 at 18:12ls -ld /path/to/directory
or simplyls -ld .
if you've already cd'd to that directory. – jsbillings Feb 15 '11 at 19:16stat -c'%G %g %a %A' .
%G is the group name, %g is the numeric group id. – jsbillings Feb 15 '11 at 19:19UNKNOWN 1002 775 drwxrwxr-x
. – tshepang Feb 15 '11 at 19:38chgrp
. – jsbillings Feb 15 '11 at 19:42UNKNOWN
thingy. – tshepang Feb 15 '11 at 19:55getent group 1002
to see if it gives you a more verbose error. – jsbillings Feb 15 '11 at 20:06