0

This question already has an answer here:

I am confused with groups in Linux. Considering that user1 is in both groups user1 and user2 (and vice versa):

user1> id user1
uid=1000(user1) gid=1000(user1) groups=1000(user1),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),50(staff),113(lpadmin),130(sambashare),131(vboxusers),1001(user2)

user1> id user2
uid=1001(user2) gid=1001(user2) groups=1001(user2),0(root),1000(user1)

I do not understand why user1 cannot edit a -rwxrw-r-- file owned by the user2 and group user2:

user1>ls -l hey.xml
-rwxrw-r-- 1 user2 user2 8385 May 24 11:39 hey.xml
user1>echo "fails" >> hey.xml 
bash: hey.xml: Permission denied

but it works when I change the group:

user1> sudo chgrp user1 hey.xml 
user1> echo "works" >> hey.xml 

Once this question is hopefully answered, what can I do to always allow user1 to read-write files in that user2 group? Thanks

marked as duplicate by Gilles, Sparhawk, Jeff Schaller, Satō Katsura, Anthony Geoghegan May 25 '17 at 8:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Did user2 log in before or after it was assigned to be a member of the user1 group? – DopeGhoti May 24 '17 at 16:08
  • I think you solved this: I did a reboot and it worked. My setup is slightly more complicated: those files are created by an export utility from an IDE in a guest Windows machine. I restarted the guest Windows machine in virtualbox, rebooted, and now user1 can Read-Write those exported hey.xml files. If you want to write a quick answer i will give you credit. Thank you! – aless80 May 24 '17 at 16:27
1

If you add a user to a group, the new membership will not take effect immediately. The easiest way to ensure this is current is to have the user whose group membership has been changed log out and back in again. Once done, the user should be able to access files as expected.

1

Ensure that the files are owned by the group both users are in. If the files already exist, use the chown utility to change ownership. It'd be a bad idea to let user1 always be able to alter files created by user2.

I'd suggest creating a new group, and adding both users to it. This will also make it easier when you go to add user3 to the mix.

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