0

I have a directory (i.e data) on a Linux machine, and it is owned by an user (i.e userone) and a group (i.e groupone) and holds a permission of 775 with setgid. Now whenever the userone creates a new directory it is not inheriting the permission of the group. I want the group's permission to be inherited whenever userone creates any new directory. How can I do this?

Now whenever a directory is getting created by userone, it loses the write permission for the group users.

0 drwxr-sr-x. 2 userone groupone   6 Dec  8 02:49 tests
1

So, you mean you want the files/directories created within that directory to inherit the permissions of the parent directory?

To do that, you need to use a default ACL (acl(5)):

If a default ACL is associated with a directory, the mode parameter to the functions creating file objects and the default ACL of the directory are used to determine the ACL of the new object:

  1. The new object inherits the default ACL of the containing directory as its access ACL.

So, with setfacl(1), the -d flag tells it to modify the default ACL:

$ ls -ld data
drwxrwsr-x+ 2 userone groupone 4096 Dec  8 18:36 data/
$ setfacl -d -m u::rwx,g::rwx,o::r-x data
$ getfacl data
# file: data
# owner: userone
# group: groupone
# flags: -s-
user::rwx
group::rwx 
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x

With that set up, a new file or directory created within the directory gets its permissions from the default ACL. This overrides the umask of the process creating the file, but doesn't override the file mode given to the open()/mkdir()/etc. system call.

$ mkdir data/test
$ ls -ld data/test
drwxrwsr-x+ 2 userone groupone 4096 Dec  8 18:38 data/test/

You may need to enable ACLs on the file system at mount time with the acl mount option.

0
-2

Setting ACLs at mount time is done via the /etc/fstab line for that mount. See man fstab for more details, it is in the 4th parameter. Possible values depend on the file system, which you can find in the man mount. For ext2/3/4 the option to add is simply acl or noacl. (The above should be a comment but I can't post comments).

1
  • 2
    ACLs are enabled by default, and enabling ACL is not the solution to the question. – RalfFriedl Dec 8 '18 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.