LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   usermod - add user to group deletes from others (https://www.linuxquestions.org/questions/linux-newbie-8/usermod-add-user-to-group-deletes-from-others-207608/)

gjhicks 07-20-2004 07:28 PM

usermod - add user to group deletes from others
 
Hi,

I want to add a user to a group but when I use [usermod -G] the user is added to the goup but deleted from the others.

For example:

say a user called Fred is in fred, groups home, office and mail. If I want to add Fred to a group called fax, I executed [usermod -G fax Fred]. Now Fred is only in groups fred and fax.

How can I add a group to a user, without losing the existing group memberships?

Regards,

Geoff.

trickykid 07-20-2004 07:38 PM

From the man pages and I made the part important in BOLD:

-g initial_group
The group name or number of the user's new initial
login group. The group name must exist. A group
number must refer to an already existing group.
The default group number is 1.

-G group,[...]
A list of supplementary groups which the user is
also a member of. Each group is separated from the
next by a comma, with no intervening whitespace.
The groups are subject to the same restrictions as
the group given with the -g option. If the user is
currently a member of a group which is not listed,
the user will be removed from the group


Basically you have to specify all the groups you want them associated with when you use usermod or it doesn't know to keep the existing groups for the user, this is how you would remove them from groups, etc.
I quite frankly find it easier to just edit the /etc/group file.

gjhicks 07-21-2004 02:18 AM

Hi,

Thanks for the reply.

I will also jusr edit the /etc/groups file.

It is a bit silly that usedmod doesn't have a switch to allow adding a group to a user.

Thanks again,

Geoff.

Flymo 06-18-2014 02:31 AM

...belatedly, I know, but there is an answer to doing this with usermod

In order to add user 'fred' to admin, do this as root (or use sudo):

Code:

# usermod -a -G admin fred
Relevant, if not that timely! ;)


All times are GMT -5. The time now is 06:36 AM.