System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to merge two user groups

SOLVED
Go to solution
josinjosek
Advisor

How to merge two user groups

Hi,

we have two user groups (smb and users) sometime we have to merge these two group( including all group privilege) sometime I have to separate these two groups. how I can perform these in HPUX.

Josin
7 REPLIES
Larry Klasmier
Honored Contributor

Re: How to merge two user groups

What exactly to you mean by merge. users can be members of more than one user group, won't that fit you needs?
Victor Fridyev
Honored Contributor
Solution

Re: How to merge two user groups

If I understand your intention correctly, you have to create the third group, called e.g smbusers and put all users from both groups into it. Each new user for both smb and users groups must be automatically added to smbusers.
In this case you can manage all needed access by assigning it to one of the below options: smb, users or smbusers.

I hope, I understand you correctly.
Entities are not to be multiplied beyond necessity - RTFM
P Arumugavel
Respected Contributor

Re: How to merge two user groups

>> sometime we have to merge these two group( including all group privilege) sometime I have to separate these two groups

Vague information on this requirement.

Victor, your way may parallel to Josin requirment.

Rgds...
josinjosek
Advisor

Re: How to merge two user groups

Thanks a lot for your response,

Currently in our server we have two groups smb and users. I also donâ t know which all are files has these group permissions. I want to give group permission of smb to all members of users group for a short period.

If I create a new group smbusers .it would be difficult for me to change all old existing files group permission. Is there any options to add/remove a group ( users ) as secondary group of other group ( smb ) ,same as â usermod â G user user1â in user administration
Bill Hassell
Honored Contributor

Re: How to merge two user groups

You can have anyone be a member of several groups at the same time:

/etc/group
smb::200:bill,dave,peggy...
users::20:bill,dave

The primary group is defined as the one listed in /etc/passwd. It can be changed at any time. The only effect of the primary group is the initial ownership of files and directories created by the user. Otherwise, the multi-group users share the same rights in each group.


Bill Hassell, sysadmin
Dan Bolton
Frequent Advisor

Re: How to merge two user groups

If I understand;
- you have a group, "smb" with specific permissions to an unknown set of files
- you want to temporarily grant the same specific permissions to all users in the group "users"
- you don't want/can't alter the permissions of the files themselves

About the only solution I can think of is to script modifying the /etc/group file, appending the members of "users" to "smb".

Below is a SAMPLE of the logic for one way you might do this. Additional checking for file integrity (grpck), max line lengths, etc. have been omitted for clarity and need to be added.

grep -v smb:: /etc/group > /etc/group.temp

SMP=$(grep smp:: /etc/group)
USERS=$(grep users:: /etc/group | cut -f 4 -d ":")
echo $SMP,$USERS >> /etc/group.temp

mv /etc/group /etc/group.orig \
&& mv /etc/group.temp /etc/group \
&& touch /etc/group.temp_in_place


And to restore the original permissions...


rm /etc/group && \
mv /etc/group.orig /etc/group && \
rm /etc/group.temp_in_place


CAUTION: unexpected results are likely to occur if the group file becomes corrupt. Use at your own risk!
...skid in sideways, chocolate in one hand, martini in the other, totally worn out and screaming, "WOO HOO what a ride!"
Dan Bolton
Frequent Advisor

Re: How to merge two user groups

Oops... typo.

Should have been:
SMB=$(grep smb:: /etc/group)
USERS=$(grep users:: /etc/group | cut -f 4 -d ":")
echo $SMB,$USERS >> /etc/group.temp
...skid in sideways, chocolate in one hand, martini in the other, totally worn out and screaming, "WOO HOO what a ride!"