1

The file and folder are owned by root but I did sudo chmod ugo+rw on both, which I confirmed with ls -l. Still, I cannot remove the file as normal user.

❯ ls -ld /tmp /tmp/perm
drwxrwxrwt 46 root root 1160 Jan  9 17:41 /tmp
-rw-rw-rw-  1 root root    3 Jan  9 17:40 /tmp/perm
❯ rm /tmp/perm
rm: cannot remove '/tmp/perm': Operation not permitted

No attr and no ACL configured:

❯ lsattr -d /tmp
---------------------- /tmp
❯ getfacl /tmp
getfacl: Removing leading '/' from absolute path names
# file: tmp
# owner: root
# group: root
# flags: --t
user::rwx
group::rwx
other::rwx

Doing the same within subfolders works.

/tmp is part of an ext4 system mounted at / running under Arch Linux.

4
  • 1
    I doubt it will be relevant, but just in case, please edit your question and include the operating system you are using and the file system of /tmp.
    – terdon
    Commented Jan 9, 2023 at 17:05
  • done, thanks for the hint :)
    – xeruf
    Commented Jan 9, 2023 at 23:58
  • /tmp of ext4 type ??? errr ??? Doesn't ArchLinux mount /tmp on a tmpfs per default ?
    – MC68020
    Commented Jan 10, 2023 at 0:23
  • @MC68020 I remember Solaris mounting /tmp on tmpfs, but I don't recall seeing Debian-based Linux distros doing that. I had to disable it on many Sun boxes back in the day. Too often large files were dumped into /tmp and used up all the RAM...
    – Sotto Voce
    Commented Jan 10, 2023 at 4:31

1 Answer 1

4

That's because the sticky bit t in /tmp: drwxrwxrwt 46 root root 1160 Jan 9 17:41 /tmp.

From man chmod:

RESTRICTED DELETION FLAG OR STICKY BIT

The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.

You can set the sticky bit by using:

chmod +t /path/to/dir

or

chmod o+x,+t /path/to/dir

The difference between both is that the first one will set T instead of t if the directory has not execution permissions for others. Whereas o+x,+t will set both the execution permissions and the sticky bit.

In this case, I do not recommend you removing the sticky bit from /tmp. But if you want to remove it you should use:

sudo chmod -t /tmp

Or better, instead of removing the sticky bit just run rm /tmp/perm as root (or sudo).

You must log in to answer this question.

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