Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I grant write permission to 1 group ?
I have 2 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?

share|improve this question
    
Do you want alex and ben to be able to create files in consult_documents and allow them both read/write access on those documents ? –  X Tian Feb 20 at 11:57

3 Answers 3

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 consult_documents, the consult_documents 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 consult_documents

or to change group ownership of everything inside the directory:

$ chgrp -R consult consult_documents

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.

share|improve this answer
    
consult_documents is a Directory then how can u specify it as a group ? –  Lonston Feb 20 at 10:16
    
@Babinlonston You can't. You specify consult as group. –  Joseph R. Feb 20 at 10:37
    
Thank you, I was looking how to give access to a directory to one group. I did not realize that the chgrp command could do this. I thought that chgrp was only to add/delete users to a group. –  anatak Feb 22 at 6:10
    
@anatak Modifying group membership is done via usermod not chgrp –  Joseph R. Feb 22 at 16:42

This will make alex and ben to colabrate each other in this Directory, And they can't collab in other Dir..

Modify the User group using

# usermod -a -G alex,ben alex

Then change the Permission for Folder

# chown alex:ben consult_documents

Check here i have worked it around

$ sudo usermod -a -G alex,ben alex

$ sudo chown alex:ben consult_documents/

cd consult_documents/

$ touch babin

drwxrwxr-x 2 alex ben  4096 Feb 20 15:19 .
drwxr-xr-x 3 alex alex 4096 Feb 20 15:17 ..
-rw-rw-r-- 1 alex alex    0 Feb 20 15:19 babin

$ su - ben

cd /home/alex/consult_documents/

ben@system99:/home/alex/consult_documents$ touch babin1
ben@system99:/home/alex/consult_documents$ ls -la
total 8
drwxrwxr-x 2 alex ben  4096 Feb 20 15:19 .
drwxr-xr-x 3 alex alex 4096 Feb 20 15:17 ..
-rw-rw-r-- 1 alex alex    0 Feb 20 15:19 babin
-rw-rw-r-- 1 ben  ben     0 Feb 20 15:19 babin1
ben@system99:/home/alex/consult_documents$

Have a look here

share|improve this answer

If I understood correctly your question, the answer is yes.

Let me explain:

Your folder and file access rights are divided into three categroies:

xxxyyyzzz
xxx are access rights for the owner
yyy are access rights for the owner's group
zzz are the access rights for everyone else

Every file and folder must be owned by a user.

Which means, if you have a folder named consult_documents, and you want it to be accessible from everyone of the group Consult, you will have this (with 755 access rights):

drwxrwxr-x Alex Consult [......]

The directory is owned by Alex, and the group is Consult. Alex has RWX access rights on it. Group Consult has RWX access rights on it. Other users have RX rights.

As your user Alex has several groups, you can choose the group to share with.

For example, if your folder is owned by Alex from groupe Alex:

drwxrwxr-x Alex Alex [......]

Do it:

chown Alex:Consult your_folder

It will become:

drwxrwxr-x Alex Consult [......]

And then the directory is available for the group Consult.

Please note that, as far as I know, you can add a group that is not one of the owner's group. But I'm not sure if it is recommended (not clear when reading access rights).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.