2

This question already has an answer here:

When I create new files and folders in a specific folder, I would like them to inherit the group and permissions of the parent folder. Is this possible ?

For example

mkdir -p example.com/public
cd example.com
sudo chgrp apache public
chmod 775 public

Now when I create a new folder

cd public
mkdir test
ls -al
drwxrwxr-x 3 foo bar 4096 Nov 3 16:19 public

The test directory belongs to foo and my default group bar. I'd like new folder to belong to the apache group instead.

I'd like the same behavior for files.

Any ideas?

marked as duplicate by Anthon, jimmij, Ramesh, jasonwryan, slm Nov 3 '14 at 23:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

The group can be inherited by setting the SGID bit:

chmod g+s /path/to/directory

For inheriting permissions you need ACL: man 5 acl

You have to set a default ACL for the directory: setfacl -d -m g::...

1

Inheriting the group ownership is easy. Simply set the SETGID bit:

chmod g+s example.com/public

Anything created in the directory should now have apache as the group owner, and directories will inherit the SETGID bit.

I don't think inheriting permissions is possible. You'll have to set the umask for your web server to set the permissions of new files/directories.

  • How does umask get saved? is it per directory? per shell session? Once umask is set on a directory, will it be used for anything that interacts with that directory? – user16614 Nov 3 '14 at 21:25
  • @naomik per shell session (in that it's usually set by the umask command): serverfault.com/questions/383734/… – muru Nov 3 '14 at 21:26
  • 1
    Default ACL values for user, group and others override the umask. – Hauke Laging Nov 3 '14 at 21:35
  • @HaukeLaging Well, assuming you can set an ACL. On Ubuntu that's been a problem for sometime, I think: help.ubuntu.com/community/FilePermissionsACLs – muru Nov 3 '14 at 21:36
  • It would be OK to mention the Ubuntu problem. The OP doesn't mention Ubuntu, though. Ignoring the obvious solution because of a problem with a single distro seems strange to me, considering that ACL have been a default mount option for years now. – Hauke Laging Nov 3 '14 at 21:45