I have the following directory structure:+ public/|-+ pics/| |-- a| `-- b`-+ thumbs/  |-- a  `-- bI would like all the files in the tree to be owned by gallery:http with ug=rwX,o= mode set.The script which happens to create directories within pics and thumbs runsas the gallery user. I set SUID/SGID bits on public, pics and thumbs.Now the problem is that the a directory will get created with owners gallery:http as it should, but it won't have the x permission for the group. If I call chmod, I'll clear the SGID bit. (Strange behavior, but thatwill really happen, likely because http is not the user-owner of the file.)I can't call chown as non-root user to set mode first and then the owners.The only solution seems to be to set umask to ug=rwx,o=, create all the directories and then either change the umask before I create any regular file, or create the regular files and then change their mode to ug=rw,o=.Is there a better, less ugly solution which I don't see?
How to call chmod and preserve the SGID bit?
linux;permissions;chown;umask;setgid
If you can change the script it might be the easiest solution to change the mkdir calls to mkdir --mode=770.If you cannot change the script then ACLs might help:setfacl -m d:u::rwx,d:g::rwx,o::- pics thumbsumask does not set executable permission on files. It never sets any permissions; it just prevents permissions from being set on file creation.