Advanced Linux file permission question (ownership change during write operation)

Posted by Kent on Super User See other posts from Super User or by Kent
Published on 2009-09-22T20:46:39Z Indexed on 2010/03/29 8:33 UTC
Read the original article Hit count: 384

Filed under:
|

By default the umask is 0022:

usera@cmp$ touch somefile; ls -l
total 0
-rw-r--r-- 1 usera usera 0 2009-09-22 22:30 somefile

The directory /home/shared/ is meant for shared files and should be owned by root and the shared group. Files created here by usern (any user) are automatically owned by the shared group. There is a cron-job taking care of changing owning user and owning group (of any moved files) once per day:

usera@cmp$ cat /etc/cron.daily/sharedscript

#!/bin/bash

chown -R root:shared /home/shared/
chmod -R 770 /home/shared/

I was writing a really large file to the shared directory. It had me (usera) as owning user and the shared group as group owner. During the write operation the cron job was run, and I still had no problem completing the write process.

You see. I thought this would happen:

  1. I am writing the file. The file permissions and ownership data for the file looks like this: -rw-r--r-- usera shared
  2. The cron job kicks in! The chown line is processed and now the file is owned by the root user and the shared group.
  3. As the owning group only has read access to the file I get a file write error! Boom! End of story.

Why did the operation succeed? A link to some kind of reference documentation to back up the reason would be very welcome (as I could use it to study more details).

© Super User or respective owner

Related posts about linux

Related posts about file-permissions