Granting write permissions to a group to a folder

filesgrouppermissions

How can I grant write permission to one group?

I have two users (alex and ben).

alex is member of group alex and of group consult.

ben is member of group ben and of group consult.

I want to grant read-write access to both alex and ben on the folder consult_documents.

If I make alex the owner of the directory consult_documents and I grant 775 access to the directory consult_documents, ben and alex will be able to access the folder, I think.

But will this allow ben access to alex's other folders as well?
If a user is in two groups, does that mean that all the members from both groups get the same permissions on all folders?

Best Answer

Granting 775 permissions on a directory doesn't automatically mean that all users in a certain group will gain rwx access to it. They need to either be the owner of the directory or to belong to the directory's group:

$ ls -ld some_dir
drwxrwxr-x 2 alex consult 4096 Feb 20 10:10 some_dir/
              ^     ^
              |     |_____ directory's group
              |___________ directory's owner

So, in order to allow both alex and ben to have write access to some_dir, the some_dir directory itself must belong to the consult group. If that's not the case, the directory's owner (alex in your example), should issue the following command:

$ chgrp consult some_dir/

or to change group ownership of everything inside the directory:

$ chgrp -R consult some_dir/

This will only work if alex is a member of the consult group, which seems to be the case in your example.

This will not allow ben to access all of alex's directories for two reasons:

  1. Not all of alex's directories will belong to the consult group
  2. Some of alex's directories may belong to the consult group but alex may not have chosen to allow rwx group access to them.

In short, the answer depends both on group ownership and on the group permission bits set for the directory.

All of this is provided you don't use any additional mandatory access control measures on your system.

Related Question