[ILUG-BOM] Inherit Ownership and Permissions

Rony Bill gnulinuxist at gmail.com
Sat Jul 15 09:14:53 IST 2017

On Jul 15, 2017 01:34, "Arun Khan" <knura9 at gmail.com> wrote:

On Wed, Jul 12, 2017 at 9:56 AM, Rony Bill <gnulinuxist at gmail.com> wrote:
> Dear Friends,
> In Linux is there a way in which new files or folders created in a
> directory will inherit the directory's owner and group with the same
> permissions too? The new files or folders are currently getting created
> with the user and group of the user who created them. I want all the new
> data to have user:group and permissions of the parent directory.
> I have tried different things like suid sgid sticky bit and even mounting
> the folder with a certain uid, gid and umask but new data does not inherit
> the same.

'setgid' should do the trick.  Note: all users must be a member of the

Here's a small test case:
user is sysadmin (sysadmin.sysadmin) *and* also a member of the 'adm' group.
Set *all* the user's umask to 0002, this will allow group members to
edit file and allow 'other' read only
Login as 'sysadmin' user.

$ cd /var/tmp/
$ mkdir testdir

$ ls -dl testdir #  should show sysadmin.sysadmin ownership
$ chmod 4775 testdir # you can change 5 to 0 if you don't want 'other'
to read the directory or files.
$ ls -dl testdir # should show setgid bit on, owner+group writable,
$ chown sysadmin.adm testdir # should show 'sysadmin.adm' ownerships.
$ cd testdir
$ mkdir yadir # user sysadmin is able to create a directory
$ ls -dl yadir # should show sysadmin.adm ownership
$ touch testfile.txt # should show sysadmin.adm ownership with rwrwr-- perms

The key thing is *consistent* umask for all members of the group.  You
will run into issues if users create dirs/files with a different umask
e.g.  0027

Arun Khan

Thanks Arun, will try it out.


More information about the Linuxers mailing list