I think what you are looking for, is to:
Use a setgid on each user's directory, so that each new file in that directory will have the same group as the directory; and
Set your system's umask
to 0002, as it appears to be 0022. umask
removes existing permissions from the default permissions, which is 0777 for directories and 0666 for files. With the new setting, the default permissions will change for files: from 0644 to 0664, and for directories: from 0755 to 0775. My understanding of the details you've given is that it will apply to your system.
To put a setgid on all the subdirectories, use the find
command as follows, but ensure that your starting directory is the one just on top of the users' directories, so that a simple ls
will list them all, as using the wrong starting directory can cause a bit of a pain reversing all that has been done:
find ./ -type d -mindepth 1 -maxdepth 1 -exec chmod --preserve-root g+s '{}' \;
The given options do the following:
-type d
returns everything of filetype 'directory';
-mindepth 1
prevents the starting directory from being listed, so that it's permissions will not change;
-maxdepth 1
lists the 1st level subdirectories, but does not go deeper into their own subdirectories;
-exec
executes the following command on every item that passes the tests, which is what '{}' stands for; and
--preserve-root
is a protection in chmod to prevent the permission change to accidentally be applied to the root directory (and potentially the whole filesystem).
If you're not sure what will be affected, simply run the find
command without the -exec
argument, like so:
find ./ -type d -mindepth 1 -maxdepth 1
, which will give you a list of every file it would pass on to whatever command you use with the -exec
argument.
Possible duplicate
With a small search I found this question may have been (partially) answered here:
How to set default file permissions for all folders/files in a directory?
The accepted answer refers to a step-by-step tutorial on how to set default permissions for a directory in https://www.linuxquestions.org/questions/linux-desktop-74/applying-default-permissions-for-newly-created-files-within-a-specific-folder-605129/
Please confirm whether this is or is not the case.