Why does this work as (not) expected?

touch filename
chown root filename
sudo chmod 700 filename
rm filename

I get asked if I want to delete the file an then!?!? The file gets really deleted! How on earth? Everybody that sits in front of my pc could easily mess up my system. I know it will rarely happen but, this is a nightmare.

rm -rf /
  • 1
    You had permission to create a file in whatever directory you touched filename, so unless you remove the group write permissions on the file, it probably won't matter who owns the file. Perhaps I'm not realizing what your pre-conditions are, but neither of the commands seem designed to break the security of OS X or any other UNIX for that matter.
    – bmike
    Jan 28, 2014 at 1:56
  • Something tells me you haven't done the research of actually trying to run rm -rf / on an OS X system while not logged in as root...
    – NReilingh
    Jan 28, 2014 at 3:57

1 Answer 1


Permissions to remove a file from a directory are not related to the file, but to the directory the file is in. Your group, or everyone, has write permissions on the directory where you are able to delete the file.

In the example below, there is a file which only root can read/write; but, user "administrator" owns the directory, and has rwx permissions. Another user ("my_user") is unable to remove the file, but "administrator" can.

sh-3.2# ls -lFa
total 0
drwxr-xr-x   3 administrator  wheel  102 Jan 28 11:12 ./
drwxrwxrwt  18 root           wheel  612 Jan 28 11:12 ../
-rw-------   1 root           wheel    0 Jan 28 11:12 a.txt
sh-3.2# su my_user
bash-3.2$ rm a.txt
override rw-------  root/wheel for a.txt? y
rm: a.txt: Permission denied
bash-3.2$ exit
sh-3.2# su administrator
bash-3.2$ rm a.txt
override rw-------  root/wheel for a.txt? y

You must log in to answer this question.

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