Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
2  
possible duplicate of Why can't I delete a file where I have group write permissions on? –  Hastur Jul 18 '14 at 22:52

1 Answer 1

up vote 20 down vote accepted

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".)

share|improve this answer
    
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 Mar 23 at 11:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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