2

I have a collection of directories that should have permissions rw-rw-r-- for all contained regular files, and rwxrwxr-x for all contained directories. I can set the default permissions for all regular files and directories with something like setfacl -R -d -m g::rw /directory/name, but this will set the default permissions for new files and new directories to the same value, which I don't want.

How can I create a chunk of the filesystem with rwx default permissions for the group, but just rw default permissions for files?

2

If you set the x flag for everything then the user "create" permissions, will also take effect. which means that typically files won't have the x flag:

$ setfacl -d -m u::rwx .
$ setfacl -d -m g::rwx .
$ setfacl -d -m o::rx . 
$ getfacl .
# file: .
# owner: sweh
# group: sweh
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x

$ mkdir DIR
$ ls -ld DIR
drwxrwxr-x+ 2 sweh sweh 4096 Aug 10 20:05 DIR
$ touch file
$ ls -l file
-rw-rw-r-- 1 sweh sweh 0 Aug 10 20:05 file
$ touch DIR/file
$ ls -l DIR/file
-rw-rw-r-- 1 sweh sweh 0 Aug 10 20:06 DIR/file

This survives umask changes:

$ umask 077
$ mkdir DIR2
$ ls -ld DIR2
drwxrwxr-x+ 2 sweh sweh 4096 Aug 10 20:08 DIR2
$ touch file3
$ ls -l file3
-rw-rw-r-- 1 sweh sweh 0 Aug 10 20:08 file3
$ > file4
$ ls -l file4
-rw-rw-r-- 1 sweh sweh 0 Aug 10 20:08 file4

The newly created directories inherit the default ACL:

$ getfacl DIR2
# file: DIR2
# owner: sweh
# group: sweh
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x

This won't remove the x flag from compiled programs, though:

$ gcc -o x x.c
$ ls -l x
-rwxrwxr-x 1 sweh sweh 6680 Aug 10 20:12 x

In this case that's because gcc does a chmod and so overrides the default:

open("x", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3
....
chmod("x", 0775) 

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.