Setting default permissions with setfacl

acldirectoryfilespermissions

I am trying to set default permissions on my directory structure using acl. I would like to have following default permissions for directories and for files respectively:

drwx--x---
-rw-r-----

but when I set default permissions for group to x only:

setfacl -R -d -m g::x my_dir

then newly created directories have my desired permissions, but newly created files have -rw------- instead of -rw-r-----. In other words, I am trying to remove r permission from directories, while preserving r permission on files.

How can I achieve this ?

Best Answer

Linux/Solaris ACLs don't support this. You can't set different default ACLs for files and directories.

Having directories that can be traversed but whose content cannot be listed (executable but not readable) is rarely useful. The fact that is works at all is a bit of a historical accident. Yes, it can occasionally be useful — but do you really need it? (You may want to ask this as a separate question.)

If you really need directories and files with different permissions, here are a few possibilities you can consider:

  • Have your application change ownership of the files that it creates instead of relying on intrinsic filesystem properties.
  • Make everything private by default (setfacl -d -m group:mygroup:X) and use one of the suggestions in Group+rx permission only in directories using ACL?:

    • Expose group-public files through bind mounts rather than directly.
    • Watch the tree with inotify and run setfacl on new regular files.
Related Question