Allow group to r/w in folder owned by a specific user

I have a group manager and an user user1.

user1 will create a directory by example in the webserver path /var/www/user1Project.

How to allow the group manager to r/w in any directory owned by user1 ?

I already tried to add group manager to user1. But it did not solved my problem. A user from manager group is not allowed to write in user1Project. I do not know why.

Answer

This is quite special and you could not manage this by using the legacy permissions architecture of an unixoid system. The closest approach to your intention is using ACLs. Issue the following command (optionally as superuser):

setfacl -d -R -m g:manager:rwx /dir/of/user1
setfacl -R -m g:manager:rwx /dir/of/user1

The first command sets the default permissions to the directory so that they apply to newly created files (by user1). The second command sets the actual rights of the folders and files recursively.

Note, that the ACL infrastructure does not apply to the Apache Webserver. Apache only cares about the legacy permissions (user/group/others permission). So inside the webfolder every file/folder must be in the www-data group and every file must have at least read permissions for www-data. Folders should have the execute permissions for www-data for the Index searching.

Update:

To force the newly created files inside a directory to inherit the group of this directory set the gid bit of the directory:

chmod g+s /web/directory

Newly created files inside /web/directory will then inherit the group of /web/directory

Attribution
Source : Link , Question Author : Atnaize , Answer Author : fragwürdig

Leave a Comment