From the post Why can rm remove read-only files? I understand that rm
just needs write permission on directory to remove the file. But I find it hard to digest the behaviour where we can easily delete a file who owner and group different.
I tried the following
mtk : my username
abc : created a new user
$ ls -l file
-rw-rw-r-- 1 mtk mtk 0 Aug 31 15:40 file
$ sudo chown abc file
$ sudo chgrp abc file
$ ls -l file
-rw-rw-r-- 1 abc abc 0 Aug 31 15:40 file
$ rm file
$ ls -l file
<deleted>
I was thinking this shouldn't have been allowed. A user should be able to delete only files under his ownership? Can someone shed light on why this is permitted? and what is the way to avoid this? I can think only restricting the write permission of the parent directory to dis-allow surprised deletes of file.
-rw-rw-rw- 1 root root 0 Sep 1 11:11 /tmp/foo
as my regular user (/tmp
is sticky`) because I am allowed to write it? Yet I cannot. – Celada Sep 01 '15 at 02:17me
/you
scenario comes into clearer focus if you hypothesize that the user (the one who doesn’t own the file) created the link. Pronouns are hard to use; let’s say Al creates/home/al/file1
, and Bob, who has execute (and maybe read) access to/home/al
, hard-links the file to/home/bob/als_file
. Should Bob be prevented from removing a link that he* created?* And should Al be allowed to delete (unlink)/home/bob/als_file
when he doesn’t have write access to/home/bob
? This road leads to chaos. – Scott - Слава Україні Sep 01 '15 at 17:38jleffler
cannot remove a file/tmp/test.sticky
that hassomeusr:somegrp:666
permissions (wherejleffler
does not belong tosomegrp
). However, on Solaris 9 (SunOS 5.9), userjleffler
can indeed remove the file. So, the behaviour depends on the platform. It may also have been subject to change — Solaris 9 is not in its first flush of youth. YMMV. – Jonathan Leffler Sep 01 '15 at 18:21