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

Problem with group membership

unixnewbie
Advisor

Problem with group membership

Hi,
I used the following command to change the secondary group of a particlar user.
/usr/sam/lbin/usermod.sam -F -G 4000 .
Now my question is whether this command will remove all other secondary group membership for that particular user or it will add the group with ID 4000 as another secondary group for the user ?
10 REPLIES
Jeff_Traigle
Honored Contributor

Re: Problem with group membership

It replaces any existing secondary group memberships with what you specify.
--
Jeff Traigle
TTr
Honored Contributor

Re: Problem with group membership

Run the command "groups " and you will see all the groups that the login-id belongs to. Apparently when /usr/sbin/usermod is called from within sam, does exactly that.
unixnewbie
Advisor

Re: Problem with group membership

Thanks Jeff, Could you tell me the otion to add one more secondary group to a user using usermod.sam ?
UVK
Trusted Contributor

Re: Problem with group membership

usermod -G

this is modify the secondary groups for a particular user.
-------------------------------------------
Like it or worked !! Click kudos !!
Mel Burslan
Honored Contributor

Re: Problem with group membership

usermod utilities are very temperamental and may or may not work at any given time. Easiest way to do this I generally use, is, edit the /etc/group file, find the group you want to add this user to, go to the end of the line and type a "," (comma) immediately follwed by the userid, no spaces or nothing else. Just follow one of the other groups in the same file for the proper format.

Word of caution, the format of the file is strict and a typo may make life miserable for other and in turn for you, but again, we are all unix admins and should know what to do. Right ? :)

________________________________
UNIX because I majored in cryptology...
unixnewbie
Advisor

Re: Problem with group membership

My problem is the users I am trying to change group membership is oracle related and root. Usermod command will not work on users that are already logged in and it is difficult to get user like oracle logged off. Thats why I want to use /usr/sam/lbin/usermod.sam which will work on users that are currently logged in.
unixnewbie
Advisor

Re: Problem with group membership

Thanks Mel for the input. Yes editing the /etc/group file was the easiest way and would have been quicker given the fact that i did this on a number of users. Still my question about the option to do it in command line remains..
Mel Burslan
Honored Contributor

Re: Problem with group membership

cat /etc/group | sed -e "/^dba/s/$/,newuser/" > /var/tmp/dummygroup
cat /var/tmp/dummygroup > /etc/group

this adds the secondary group membership for "dba" group, to the userid "newuser"

you can script these two commands as your heart desires.

hope this helps
________________________________
UNIX because I majored in cryptology...
Jeff_Traigle
Honored Contributor

Re: Problem with group membership

Using TTr's reference to the groups command, you could do this to add a secondary group without eliminating current memberships:

CUR_GROUPS=$(groups -g jtraigle | sed 's/ /,/g')
/usr/sam/lbin/usermod.sam -F -G ${CUR_GROUPS},4000
--
Jeff Traigle
unixnewbie
Advisor

Re: Problem with group membership

Thanks Mel and Jeff for the scripts.
I was under the assumption that usermod -G or usermod.sam -G will add the user to a secondary group keeping the current groups intact.

UVK, what Jeff told is right. It will replace the group list. Even usermod does so..
# usermod -G 4001 test

# id test
uid=101(test) gid=20(users) groups=4001(oper)

# usermod -G 4000 test

# id test
uid=101(test) gid=20(users) groups=4000(operm)