I own a particular file on a Linux system. I would like to give 2 groups (accounting, shipping) read access and only read access, and 3 users(Mike, Raj and Wally) write access and only write access.

How can I accomplish this?

link|improve this question
2  
Question for superuser – Drakosha Jul 8 '10 at 5:48
1  
Sounds more like ServerFault to me--- Multi-user and all. – Reece45 Jul 8 '10 at 6:14
@AlReece45 I disagree. This is specific to linux operating systems and has nothing to do with administering a network so it should remain on Super User. – Evan Plaice Jul 8 '10 at 6:55
feedback

migrated from stackoverflow.com Jul 8 '10 at 6:18

This question came from our site for professional and enthusiast programmers.

3 Answers

I suggest using POSIX ACLs (Access Control Lists). Your filesystem must support them / have the acl option enabled, but if it does, then your problem simplifies to:

setfacl -m u:mike:w myfile
setfacl -m u:raj:w myfile
setfacl -m u:wally:w myfile
setfacl -m g:accounting:r myfile
setfacl -m g:shipping:r myfile

And you can do that for arbitrary sets of permissions.

link|improve this answer
feedback

group read access, specify the second bit as 4, but what is that 3 users ?

chmod 240 file

write to user, read to group.

link|improve this answer
Sorry for the confusion. Check the edit. – Warren Jul 8 '10 at 6:04
feedback

If you have 2 groups A,B and 3 users x,y,z

first give the correct ownership:

for the group:

chgrp A my_file

for the user

chown x my_file

then change permissions:

chmod g+r my_file # for the group

chmod u+w my_file # for the file
link|improve this answer
1  
I don't think this lets group B read the file. – Borealid Jul 8 '10 at 6:12
Yes he must does the same operations also for B,C y and z... – xdevel2000 Jul 8 '10 at 7:59
1  
No, a file can only have one owner/group at a time. – Dennis Williamson Jul 8 '10 at 9:07
feedback

Your Answer

 
or
required, but never shown