I create a folder for example /tmp/foo . I put on her rights 775 . Accordingly, for this I chmod -R 775 /tmp/foo running chmod -R 775 /tmp/foo . I make the user myuser and the group 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 should inherit the owner and access rights from it. If I create, for example, the file /tpm/foo/bar.txt , it should also have the same rights as 775 and the owner of myuser group mygroup . Even if the file is created by another user from the mygroup group.

I tried to do chmod -R 4775 /tmp/foo anyway, the 755 right created inside the file and the owner of otheruser group otheruser . Names of users and groups conditional. What am I doing wrong?

  • Catalog mountable? If yes, then the rights must be set after mounting. And the rights are set when you create a file / directory note. - Adokenai
  • I know about @Adokenai about rights after mounting. No, the directory is not mountable. It is created once and for all. And about the rights to create .. do not quite understand. mkdir with the -m option? Well, OK. And if after creation to make chmod it not that? - Captain Flint
  • when rights are assigned, creator rights are used for new directories and files. That is, on whose behalf the owner was created. chmod can always be done. PS if we are talking about tmpfs, then there are some troubles, because the temporary directory in memory. - Adokenai pm
  • It's impossible. The owner is always the one who creates. The rights are set to those specified in the user's umask. - Mike

1 answer 1

But there is a task: all new files and folders (conditionally infinite nesting) inside / tmp / foo should 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 is not practical. In linux, as in most unix-like operating systems, setting the setuid bit on the directory does not have any effect — the owner is always the creator of the file.

On the other hand, you can inherit a group of a file; the setgid bit is used for this:

 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 by the umask user processes. In order to set the default permissions, you can set the default ACL values.

 setfacl -md:u::rwx /tmp/foo setfacl -md:g::rwx /tmp/foo 

These values ​​act like ~ umask (i.e., addition to umask ) in this directory, modifying the rights requested by the process when creating the file / subdirectory. Those. Any process can request to create a file with less permissions, but usually most programs try to create a file with permissions 0666 , and directories from 0777 . These values ​​are also inherited by subdirectories.