Weird rm behaviour

I am little bit confused by the behaviour of rm in Ubuntu.

It seems that as a regular user I can delete files owned by another user even when the permissions are set to 644.

Here is an example:

cjohnson@carbon:~/test$ sudo touch testfile
cjohnson@carbon:~/test$ ls -al
total 8
drwxr-xr-x  2 cjohnson cjohnson 4096 2011-12-01 11:21 .
drwxr-xr-x 64 cjohnson cjohnson 4096 2011-12-01 11:21 ..
-rw-r--r--  1 root     root        0 2011-12-01 11:21 testfile
cjohnson@carbon:~/test$ rm testfile
rm: remove write-protected regular empty file `testfile'? y
cjohnson@carbon:~/test$ ls -al
total 8
drwxr-xr-x  2 cjohnson cjohnson 4096 2011-12-01 11:21 .
drwxr-xr-x 64 cjohnson cjohnson 4096 2011-12-01 11:21 ..
cjohnson@carbon:~/test$

Anybody have an explanation?

Should have added this:

uname -a
Linux carbon 2.6.32-24-server #43-Ubuntu SMP Thu Sep 16 16:05:42 UTC 2010 x86_64 GNU/Linux

unlink (and create) permission is determined by the directory, not the file.

1 Like

Yeah, just figured that one out. I guess I learned that many years ago and just forgot.

Thanks