This question is a good fit for linux acl
. Since you don't state your OS, I'll assume Linux in what follows. Here is an example session.
I don't know of a really good acl
tutorial, but you could do worse than "Using ACLs with Fedora Core 2 (Linux Kernel 2.6.5)" by Van Emery.
Note that the default acl
behaves like a local umask. Since at least in Linux, umasks are applied globally, this is the only way I know to get the effect of a local umask. For some reason this a little known feature. The net is littered with people asking about a local umask override, but almost nobody seems to think of using acl
.
Also note that you need to mount the partition you are working in with acl
support, eg.
/dev/mapper/debian-acl /mnt/acl ext3 defaults,acl 0 2
Session follows:
/mnt/acl$ mkdir foo
/mnt/acl$ getfacl foo
# file: foo
# owner: faheem
# group: faheem
user::rwx
group::r-x
other::r-x
Set the group of foo
to be staff
, and set the acl of group and user of foo
to rwx
.
/mnt/acl$ chgrp staff foo
/mnt/acl$ setfacl -R -m u::rwx,g::rwx foo
/mnt/acl$ getfacl foo
# file: foo
# owner: faheem
# group: staff
user::rwx
group::rwx
other::r-x
Set default acls of user and group to rwx
as well. This defines permissions that files and directories inherit from foo
. So all files and directories created under foo will have group permissions rw
.
/mnt/acl$ setfacl -d --set u::rwx,g::rwx,o::- foo
/mnt/acl$ getfacl foo
# file: foo
# owner: faheem
# group: staff
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::---
Now create some files in foo
as users faheem
and john
.
/mnt/acl$ cd foo
/mnt/acl/foo$ touch bar
# switch to user john for this next command.
/mnt/acl/foo$ touch baz
List files. Notice that both files owned by faheem
and files owned by john
are created with group permissions rw
.
/mnt/acl/foo$ ls -la
total 3
drwxrwxr-x+ 2 faheem staff 1024 May 9 01:22 .
drwxr-xr-x 4 faheem faheem 1024 May 9 01:20 ..
-rw-rw---- 1 faheem faheem 0 May 9 01:20 bar
-rw-rw---- 1 john john 0 May 9 01:22 baz