I have a directory called "members" and under it there are folders/files. How can I recursively set all the current folders/files and any future ones created there to by default have 775 permissions and belong to owner/group nobody/admin respectively? I enabled ACL, mounted, but can't seem to get the setfacl command to do this properly. Any idea how to accomplish this?

up vote 42 down vote accepted

I actually found something that so far does what I asked for, sharing here so anyone who runs into this issue can try out this solution:

sudo setfacl -Rdm g:groupnamehere:rwx /base/path/members/
sudo setfacl -Rm g:groupnamehere:rwx /base/path/members/

R is recursive, which means everything under that directory will have the rule applied to it.
d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules.

The first command, is for new items (hence the d), the second command, is for old/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.

  • 1
    This is exactly what I needed to get the owner of a grandparent directory to be able to properly modify the contents of new grandchild directories. – Joost Aug 18 '15 at 7:01
  • If you are the only user of your Rpi, you can replace g:groupname with pi:pi or just pi – SDsolar Mar 11 '17 at 22:30

To go with your accepted answer ...

You can combine those commands together as:

sudo setfacl -Rm d:g:groupnamehere:rwx,g:groupnamehere:rwx /base/path/members/
  • Thats cool. How come you set d: on the first item rather than -Rmd? I can tell that the second parameter should have no default -- it's just odd how linux accepts it to me. – JREAM May 2 '17 at 3:12
  • @JREAM: Linux (actually getopt_long) sends the whole argument to option -m which is parsed by hand by setfacl, separating by commas the passed arguments. They are added to a linked list which is looped through at the end when actually changing the ACL. – Benoit Duffez Jun 28 '17 at 8:04

setfacl on linux has the -d and -k options for manipulating default permissions which are probably what you are looking for (see man for more info).

It is easy to recursively set simple UNIX permissions at upon demand of an appropriately authorized user, the permissions of directories and files. It is not possible to automatically impose this.

You could tell users to use the set the umask of 0002, and that helps to make new files at 0775 (depending on the application). But it is not enforcable.

My understanding is that ACLs are not inherited on UNIX/Linux systems. They are set upon demand.

As for file/directory ownership, you are pretty much out of luck here.

As for file/directory group ownership, by setting the directory set-gid bit (i.e. g+s on DIRECTORIES), this does cause the group ownership to be inherited.

What I have done in such situations is to execute a periodic root cron script which resets non-conforming permissions/ownerships to the standard in such directories.

Another (NOT RECOMMENDED) process is to have the same user-id be used when working on these files. This could be accomplished by the user logging into the system under his own UID, and then using sudo or su to run as the id. This still is not 100% especially concerning ACLs and permission bits.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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