0

I have a NAS with a directory for each member of my house.

My user name, is member of each member's group. So I have access to folders of all users.

I want, when I place a file, inside a user's directory, the file take the ownership from parent directory. Or get specific permissions.

Directory of my wife is "zoe_folder" with ownership zoe:zoe and permissions rwxrwx---.

When I run e.g. as root the command touch file.txt inside my wife's directory (or subdirectories), then file.txt has ownership root:root and permissions rw-r--r--. I want ownership zoe:zoe (or as workaround permissions rw-rw-rw-).

And of course without run any of commands chmod, chown. It is a NAS and client PCs are Windows. I cannot login every time in NAS with console and change permissions.

Any ideas?

1
  • Have you considered ACLs (Access Control Lists) as potential alternative? I'm not at all familiar with them beyond awareness of the existence, but it seems to be the cross-platform solution you're looking for, and I do know that both Windows and Linux can use ACLs.
    – Mr. Donutz
    Jan 11, 2020 at 13:17

1 Answer 1

1

I think what you are looking for, is to:

  1. 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

  2. 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.

1
  • Yes! I missed umask for system level! So, umask 0002 (edit /etc/login.defs for permanent modification does not do permanent modification. How can I permanent change umask to 0002?) then chmod g+s MyWifesFolder. Above is useful when create files from console. If you using SAMBA then edit etc/samba/smb.conf create mask = 770 directory mask = 770 and then service smbd restart. umask stuff is not needed for samba.
    – Chameleon
    Jan 11, 2020 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .