I created a file, did chmod 000 to it and then changed the owner and group to root:root. I was still able to delete the file as the original creator of it (not root).
Who has permissions to delete a file?
The permissions of the containing directory determine the ability to rename and delete files.
Specifically, to delete/rename a file, a user needs to have write and execute (i.e. traversal) permissions on the containing directory, and the file in question must not be immutable. (Under these circumstances, a non-privileged user can even delete files owned by root.)
It is possible to restrict deletion of files to only the owner of the files (and privileged users), by setting the 'sticky bit' (also known as the 'restricted deletion flag') on the containing directory using:
You should note that the read permission on the containing directory is not required. Without it, you will still be able to delete the file, if you know its name, although you will not be able to 'read' the contents of the directory (e.g. without read permissions you cannot run
As a side point, by making a file immutable (i.e.
The owner of the folder where the file resides will, if they have write permissions on the folder, be able to delete the file even if it's mask is 000 or the file is owned by another user. If you really want to create a file that no one can touch/delete you should look into the command
From the documentation: