Linux - group member cannot delete file with rw permission

15

7

Below shows a file, /tmp/testfile, owned by user1 with group changed to wheel that also includes user2. The file has rw permission for the group. So shouldn't any member of the group be able to delete it? The example output below shows that user2 is not able to delete the file. Why?

[user2@files ~]$ ls -l /tmp/testfile
-rw-rw-r-- 1 user1 wheel 0 Jul 18 18:54 /tmp/testfile
[user2@files ~]$ groups
user2 wheel
[user2@files ~]$  rm /tmp/testfile
rm: cannot remove `/tmp/testfile': Operation not permitted

user347765

Posted 2014-07-18T19:18:44.170

Reputation: 161

2

possible duplicate of Why can't I delete a file where I have group write permissions on?

– Hastur – 2014-07-18T22:52:11.833

Furthermore to the complete explanation by @grawity, a good solution is to create your 'own' directory under tmp and fix the sticky situation – fcm – 2017-10-12T17:28:38.967

Answers

31

First, you're looking at the wrong permissions. When you move/rename/delete a file, you're only modifying the parent directory – the file's own permissions are not checked. You only remove an entry from the directory's list of files. Therefore you should check the permissions of the parent directory (in this case /tmp).

$ ls -ld /tmp
drwxrwxrwt 15 root root 460 Jul 19 15:18 /tmp/

Second, /tmp is special. On practically all systems, it's writable by anyone (ugo=rwx), so at first glance, it looks like anyone could rename or delete any file in it. This would of course make it easy (well, even easier) to create problems for other users, therefore /tmp always has the "sticky" aka "restricted deletion" mode set (o+t). With this mode set, only the file's owner can move or delete files in that directory, regardless of any permissions.

(On GNU coreutils, the chmod(1) manual page has a section about the "restricted deletion flag or sticky bit".)

user1686

Posted 2014-07-18T19:18:44.170

Reputation: 283 655

I'm facing the same issue due to second point of special sticky permission. I tried to remove it chmod o-t /tmp and then re-tried to delete the file, but it is still complaining the same. – Shashank Agrawal – 2015-03-23T11:43:43.610

1Not only the file owner can delete files under said directory, but also root and the owner of the directory (e.g. /tmp). – wulfgarpro – 2015-12-09T22:13:47.220