Inheritance of linux directory rights
Creating a folder for example /tmp/foo
. I put up the rights to it 775
. Accordingly, to do this, I perform chmod -R 775 /tmp/foo
. I make the user myuser
and the group the owner mygroup
: chown -R myuser:mygroup /tmp/foo
. This is clear and understandable. But there is a task: all new files and folders (conditionally infinite nesting) inside /tmp/foo
must inherit the owner and access rights from it. If I create for example a file /tpm/foo/bar.txt
, it must also have the rights 775
and the owner myuser
group mygroup
. Even if the file is created by another user from groups mygroup
.
I tried to do chmod -R 4775 /tmp/foo
all the same, the rights created inside the file 755
and the owner otheruser
group otheruser
. The names of users and groups are conditional. What am I doing wrong?
1 answers
But there is a task: all new files and folders (conditionally infinite nesting) inside /tmp/foo must inherit the owner and access rights from it.
In short, it is impossible to inherit the owner (without changes in the linux kernel) and for the most part it makes no practical sense. In linux, as in most unix-like operating systems, setting the bit setuid
it has no effect on the directory - the owner is always the creator of the file.
On the other hand you can inherit a file group by using the bit setgid
:
chmod g+s /tmp/foo
After that, the subdirectories / files will inherit the group and the setgid
bit, but the rights will still be determined umask
'om of user processes. To set the default rights, you can set the values "ACL by default" (default ACL).
setfacl -m d:u::rwx /tmp/foo
setfacl -m d:g::rwx /tmp/foo
These values act similarly to ~umask (i.e., the complement to umask
' y) in this directory, modifying the rights requested by the process when creating a file/subdirectory. I.e., any process can request the creation of a file with lower rights, but usually most programs try to create a file with 0666
rights, and directories with 0777
. These values are also inherited by subdirectories.