6

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.. :/

2 Answers 2

14

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.

7
  • yap! got it! This is really strange. Can not get it why it is implemented this way. Jun 16, 2010 at 13:40
  • 4
    @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.
    – Jarvin
    Jun 16, 2010 at 14:13
  • MM! What good is setting o+r field on directory, without setting o+x? Jun 16, 2010 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, 2010 at 14:35
  • @0xDEAD: A directory with only +r is not very useful. On the other hand, having only +x without +r is used quite often. Jun 16, 2010 at 16:36
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .