It is not possible to have a file owned by multiple Linux groups with traditional Unix permissions. (However, it is possible with ACL.)
But you might use the following workaround and create a new group (e.g. called devFirms
) which will include all users of the groups devFirmA
, devFirmB
and devFirmC
.
You create new user groups with:
sudo addgroup NEWGROUPNAME
First, you might have to install id-utils
to get the lid
-command:
sudo apt-get install id-utils
Then you can run the following line of code to easily copy all users of SOURCEGROUP
to TARGETGROUP
. Of course you have to run the command once for each group you want to copy. Don't forget to replace the capitalized place-holders with the actual group names.
for u in $(lid -g -n SOURCEGROUP); do sudo usermod -a -G TARGETGROUP $u; done
So in your case you would have to run the command (all lines at once):
sudo addgroup devFirms &&
for u in $(lid -g -n devFirmA); do sudo usermod -a -G devFirms $u; done &&
for u in $(lid -g -n devFirmB); do sudo usermod -a -G devFirms $u; done &&
for u in $(lid -g -n devFirmC); do sudo usermod -a -G devFirms $u; done
Note that these commands only copy all users who are current members of the source groups. Every user who gets added later will also have to be manually added to your common group with the adduser
command. Just replace once again the capitalized place-holders with the actual user and group name (devFirms
):
sudo adduser NEWUSER TARGETGROUP
Thanks to Justin Ethier for his answer at Unix&Linux.SE: Add all users of one group to another group?