ubuntu remove file with full permissions

Posted on

Problem :

I created a file in the /tmp/ directory. The file is owned by mysql user and has full permissions, i.e.

-rw-rw-rw- 1 mysql  mysql    16 Sep 23 12:44 artists.csv

Now I want to delete it, but get Operation not permitted error:

shimon@T61p:~$ rm /tmp/artists.csv 
rm: cannot remove ‘/tmp/artists.csv’: Operation not permitted

I only can delete this file using sudo.
I want to know why I cannot delete file which has all permissions for that using my user.

Output of getfacl artists.csv:

shimon@T61p:/tmp$ getfacl artists.csv
# file: artists.csv
# owner: mysql
# group: mysql
user::rw-
group::rw-
other::rw-

Solution :

After googling around I found the issue:
The /tmp folder has the sticky bit special permission:

drwxrwxrwt  11 root root 36864 Sep 23 14:12 tmp

Note the t at the end of permissions – this means that the sticky bit is set. When the sticky bit is set, any user can create files, but only the owner of a file can delete it.labor-liber.org

From Ubuntu Support:

Within a directory upon which the sticky bit is applied, users are prevented from deleting or renaming any files that they do not personally own.

Leave a Reply

Your email address will not be published. Required fields are marked *