LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 04-17-2011, 01:22 AM   #1
nooneknowme
Member
 
Registered: Feb 2008
Location: Bangalore, India
Posts: 69

Rep: Reputation: 5
Change user's primary and secondary group


I am working on SLES11 and noticed a strange thing. Whenever I try to swap a user's primary group to become it's secondary group, and assign a new primary group with usermod, it does not change. Only the primary or the secondary changes.


I am using -g and -G in the same command.

If I run the same command twice, the work is done.

Just curious if anyone knows why.

Last edited by nooneknowme; 04-17-2011 at 01:27 AM.
 
Old 04-17-2011, 09:04 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

It is because the default behaviour of -G is to add the group that follows it so if you are not mentioning the existing group then it will remove the group already assigned to that user.

For example if the user test is the member of test group and I run the command usermod -G manager test. This will make the test member of manager group. However, it will remove test from the membership of test group. To overcome this you can use -a with -G switch which will append the group.

As you said it works when you run the command second time because in the same command that group is mentioned along with the new group that you want to add.

Just concatenate the commands if you want to get it done in a single line ;-)
 
  


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
How to change a primary partition into secondary in ubuntu 10.04 dins Linux - Newbie 5 11-04-2010 11:10 AM
How do I change a user's primary group? Akhran Linux - Newbie 4 03-19-2010 08:54 PM
Secondary group users need to change the file permissions of primary group files? sunnybmv Linux - Newbie 3 12-10-2009 04:57 PM
script to change primary group. stian Linux - Newbie 10 08-04-2009 02:05 PM
Primary and secondary group trophy Linux - Newbie 2 04-03-2004 12:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 07:10 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