Situation as follows: i do su to root, then i create admin file with

cat > adminfile

then i exit from root issuing exit command

i can see following adminfile options

-rw-r--r-- 1 root root 10 2010-06-16 16:25 adminfile

however, after executing rm adminfile it really gets removed

-rw-r--r-- 1 root   root   10 2010-06-16 16:25 adminfile
reinis@reinis-desktop:~/Test/script$ rm adminfile
rm: remove write-protected regular file `adminfile'?

tada.. file is gone!

As i see it - others have only read permision for that file so they shouldnot be able to remove it.. :/

link|improve this question

75% accept rate
feedback

2 Answers

up vote 10 down vote accepted

You have write permission on the directory so you can remove any file from it.

Deleting or creating a file is modifying the directory so you need appropriate permissions on the that, rather than the file itself. If you want to be able to modify the file, you'll need write permissions on the file.

Similarly, you need read permission on a directory before you can see which files are in that directory and then you'll need read permission on the files themselves if you want to see what in each file.

link|improve this answer
yap! got it! This is really strange. Can not get it why it is implemented this way. – 0xDEAD BEEF Jun 16 '10 at 13:40
2  
@0xDEAD Think of a directory as a text file that is a list of everything in that folder. If you have write access to it you can delete one of the entries. – Dan Jun 16 '10 at 14:13
MM! What good is setting o+r field on directory, without setting o+x? – 0xDEAD BEEF Jun 16 '10 at 14:14
However, if the directory has the sticky bit set, then only the owner of the file can remove it. – petersohn Jun 16 '10 at 14:35
@petersohn: incorrect - the directory's owner can remove files anyway. Sticky only prevents other users from removing files (in case of world-writable directory). – grawity Jun 16 '10 at 16:36
show 3 more comments
feedback

The owner of a directory is allowed to delete any files owned by other users.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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