LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-14-2005, 08:22 PM   #1
Akhran
Member
 
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Rep: Reputation: 30
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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-14-2005, 08:28 PM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
You probably meant -g. man usermod.
 
Old 11-15-2005, 04:36 AM   #3
Akhran
Member
 
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Original Poster
Rep: Reputation: 30
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.
 
Old 10-30-2007, 08:51 PM   #4
aloneattack
LQ Newbie
 
Registered: Aug 2007
Posts: 11

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

usermod -G <the_only_primary_group> <user>
 
Old 03-19-2010, 08:54 PM   #5
mycrazydream
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 1
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
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to set different quota depending on User's Group ID TechNett Programming 6 08-09-2004 02:45 PM
Changing user's group? orange400 Linux - General 2 06-18-2004 04:30 AM
Primary and secondary group trophy Linux - Newbie 2 04-03-2004 12:30 AM
Changing a user's default group dogn00dles Linux - Security 4 07-09-2003 03:59 PM
What is a Primary Group? ejtbrown Linux - General 2 03-21-2001 04:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration