I run the following commands on a new VM:

$ sudo adduser banana
Adding user `banana' ...
Adding new group `banana' (1034) ...
Adding new user `banana' (1033) with group `banana' ...
$ sudo touch /tmp/test.txt
$ sudo chmod 666 /tmp/test.txt
$ python3 -c "open('/tmp/test.txt', 'w')"
$ sudo chown banana:banana /tmp/test.txt
$ python3 -c "open('/tmp/test.txt', 'w')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/tmp/test.txt'

On Ubuntu 20.04 and Debian 11, I get permission denied when trying to open a file owned by someone else. On CentOS 8.2 and Debian 10, the last line succeeds. Weirdly, if the file is owned by root, I can open it for writing, but not if it's owned by some other user. Reading works fine either way.

$ lsattr /tmp/test.txt
--------------e------- /tmp/test.txt

What is going on?



Browse other questions tagged .