LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I change a user's primary group? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-change-a-users-primary-group-383193/)

Akhran 11-14-2005 08:22 PM

How do I change a user's primary group?
 
I have a user 'Peter' with primary group 'users'. I want to change his primary group from 'users' to 'nogroup' with
Code:

usermod -G nogroup Peter
However, what the command did was to add 'nogroup' to Peter as a secondary group. Is there any way to change a user's primary group after the userid's creation?

Thanks.

sigsegv 11-14-2005 08:28 PM

You probably meant -g. man usermod.

Akhran 11-15-2005 04:36 AM

Code:

usermod -g nogroup printuser
This command assigns nogroup as the primary group of printuser, which is what I want, but it also demote the original primary group 'users' to be the secondary group.

Is there a command to assign 'nogroup' as the new primary group with no secondary group?

Thanks !


Quote:

Originally posted by sigsegv
You probably meant -g. man usermod.

aloneattack 10-30-2007 08:51 PM

After you change the primary group for user successful, then issue:

usermod -G <the_only_primary_group> <user>

mycrazydream 03-19-2010 08:54 PM

Handily change the current user's primary group
 
I've tried a variety of all of these, and I must warn others - be careful.

The following command will change a user's primary group. All set?

Code:

usermod -g group user
Unfortunately, this will also remove any other group associations the user had. One can quite easily remove all of one's superuser access with this command.

If you simply want to add a user to a supplementary group (retaining existing groups) run this.

Code:

usermod -a -G group user
The -a is a recent addition, allowing for the retention of existing groups. You could go into /etc/passwd and change the group id associated with the user. This didn't work for me even after restarting the shell. The command that worked perfectly for me, was quite easily:

Code:

newgrp group


All times are GMT -5. The time now is 11:08 PM.