Operating System - HP-UX
1833256 Members
2993 Online
110051 Solutions
New Discussion

is there a command to remove a user from a group?

 
SOLVED
Go to solution
B. Chapman
Frequent Advisor

is there a command to remove a user from a group?

SysAdmins,

I'm writing custom scripts for our hotline folks to add/remove member(s) from /etc/group - and I have two questions:

(1) When executing "usermod -G $GROUP $ID", *why* does it always automatically add $ID to the "users" group (all of my ID's are in the "users" group via their primary GID found in /etc/passwd - and I don't want them getting added to "users" in /etc/group).

(2) Is there a "reverse" of the command "usermod -G ..." that would REMOVE a user from a group - or am I going to be forced to use 'sed'...

Thanks in advance!
Ben Chapman
bchapman@telcordia.com
8 REPLIES 8
hpuxrox
Respected Contributor

Re: is there a command to remove a user from a group?

I could be proven wrong, but it looks like its time to practice some sed.

-Yates
David Burgess
Esteemed Contributor
Solution

Re: is there a command to remove a user from a group?

When I do

usermod -G sys dburgess

I don't get dburgess added to the users line in /etc/group

To take dburgess out of the sys group do :-

usermod -G "" dburgess

HTH

Dave.
John Carr_2
Honored Contributor

Re: is there a command to remove a user from a group?

Hi

I dont seem to suffer from the same problem as you if I am understanding your problem see below.

# cd /etc
#
#
# cat group
root::0:root
other::1:root,hpdb
bin::2:root,bin
sys::3:root,uucp
adm::4:root,adm
daemon::5:root,daemon
mail::6:root
lp::7:root,lp
tty::10:
nuucp::11:nuucp
users::20:root,john
nogroup:*:-2:
oracle::101:
opcgrp::77:
#
# usermod -G 101 john
#
# cat group
root::0:root
other::1:root,hpdb
bin::2:root,bin
sys::3:root,uucp
adm::4:root,adm
daemon::5:root,daemon
mail::6:root
lp::7:root,lp
tty::10:
nuucp::11:nuucp
users::20:root
nogroup:*:-2:
oracle::101:john
opcgrp::77:
#
# uname -a
HP-UX master B.11.00 A 9000/778 2002465323 two-user license
#


As you will see I moved from users to oracle and no duplicate entries !!!!

cheers
John.
John Carr_2
Honored Contributor

Re: is there a command to remove a user from a group?

Hi

I just tried Davids method and it removed me from my users group

usermod -G "" john

cheers
John
hpuxrox
Respected Contributor

Re: is there a command to remove a user from a group?

I tested and it sure does,
Darrell Allen
Honored Contributor

Re: is there a command to remove a user from a group?

Hi Ben,

I'm not sure I follow. Sounds like you want to modify the primary group for a specified user. That would be the "-g" option of usermod.

The "-G" option modifies their secondary group.

Maybe you could include a specific example (with the names, etc changed, of course).

Are your patches up-to-date? What OS release are you on?

I believe "-G" will delete the user from all secondary groups except those specified. I don't know of a command that removes the user from a specific group while leaving him in others.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
B. Chapman
Frequent Advisor

Re: is there a command to remove a user from a group?

OK - Thanks a million - I'll assign points right after this posting:

-Unfortunately I'm still on HP-UX 10.20 (ulp!) - and this "users" problem is related to that - because I tested on 11.0 and got the same results you all got - IT WORKED as it should. I'll have to deal with this as a separate case...

-Many thanks for the usermod -G "" ID command (using a null group) - that will take the ID out of /etc/group.

Looks like another reason to move off of 10.20. Now if only Oracle 11i would behave, WE COULD GET UPGRADED!

Later,
Ben
James R. Ferguson
Acclaimed Contributor

Re: is there a command to remove a user from a group?

Hi:

You must be running 10.x. Prior to 11.0, an entry in /etc/group was made for the primary group of each user. This does not (and need not) occur at 11.x.

Regards!

...JRF...