15

In Ubuntu 18.04, I can create a file as one user in /tmp, and write to it as user root (despite the sticky bit being set on /tmp).

In Ubuntu 20.04, I get a Permission Denied error as user root.

Ubuntu 18.04:

# As user "ubuntu":
touch /tmp/tmplock

# As user "root":
echo "foo" > /tmp/tmplock

cat /tmp/tmplock
# Outputs "foo"

ls -lah /tmp
drwxrwxrwt 32 root   root    20K Jun 16 18:36 .
-rw-rw-r--  1 ubuntu ubuntu    4 Jun 16 18:36 tmplock

Ubuntu 20.04:

# As user "ubuntu":
touch /tmp/tmplock

# As user "root":
echo "foo" > /tmp/tmplock
# Outputs: bash: /tmp/tmplock: Permission denied

ls -lah /tmp
drwxrwxrwt 12 root   root   4.0K Jun 16 18:15 .
-rw-rw-r--  1 ubuntu ubuntu    0 Jun 16 18:14 tmplock

I can't find any information on if this is related to the sticky bit, or an underlying Linux kernel change, or anything.

Does anyone know what can explain the change in behavior?

16

To change the behavior back to the 18.04 default:

sudo sysctl fs.protected_regular=0  

See the accepted answer to

https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp

Sigh, sometimes the cure is worse than the disease.

0
1

The root user should always be able to edit any and all files. The only correct response is to disable the sysctl fs.protected_regular setting until it gets fixed (i.e. so that root can edit anything on the system).

The other answer has a temporary solution that doesn't stick between reboots.

If you want to make the fs.protected_regular=0 change permanent between reboots, edit the /usr/lib/sysctl.d/protect-links.conf file.

Make the above change, then save and reboot to verify that it is working as expected.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.