Re: Inherit Ownership and Permissions

Arun Khan <[email protected]>
Newsgroups gmane.user-groups.linux.mumbai
Message-ID <CAHhM8gA4RmvXaUcA+1EqctRBuDjviWk5UjBwh=+c01u3n5hFNQ@mail.gmail.com>
On Wed, Jul 12, 2017 at 9:56 AM, Rony Bill <[email protected]> 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 group.

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

HTH.
--
Arun Khan
-- 
http://mm.ilug-bom.org.in/mailman/listinfo/linuxers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.