LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-23-2009, 09:06 AM   #1
bar338
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
useradd and multiple group question


This is what i'm trying to do:
create a new user
add them to a primary group
add them to a couple secondary groups

The command i'm using right now

useradd -g developers <username>

this works but when i try to add secondary groups I get an error (I also want the users group to be a part of the secondary group.

useradd -g developers -G <username>,admins,wheel <username>

Does this make sense? and is it possible to do all this in one command? I'm currently able to do it but I have to perform a usermod command after I add the user. I think the real problem is adding the <username> group as a secondary group while the user is being created.

Thanks for your help.
 
Old 11-23-2009, 09:22 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello and welcome to LinuxQuestions,

The best info to start with is the man page for useradd:
Code:
man useradd
If you add a user with the useradd commando the you can specify a primary group with the -g and additional groups with the -G option:
Code:
-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  white-
              space.  The groups are subject to the same restrictions as the group given with the -g option.  The default is for the user to belong only to the
              initial group.
So if you want to add a user and set as primary group developers and as secondary group(s) print, sshd, etc...:
Code:
useradd username -g developers -G print,sshd,etc
Kind regards,

Eric
 
Old 11-23-2009, 09:43 AM   #3
bar338
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Yes I understand this but I think I need to be more clear as to what my main question is.

Typically when you create a new user on my server and don't include any extra parameters it assigns the person to the <username> group. For example, if I add a user called jsmith his primary group will be jsmith.

Now I want to add a different primary group called developers for jsmith and add the group jsmith as a secondary group. I think the problem might be that when running a single command, which includes creating the user and assigning the 'jsmith' group as a secondary group, the secondary group can't be assigned because It hasn't been created yet at the point of the useradd command. Am I correct in understanding this? If so then I will have to use two commands to perform this action.

My exact command
sudo useradd jsmith -g developers -G jsmith,admins
Error message:
useradd: invalid numeric argument 'jsmith'
 
Old 11-23-2009, 10:05 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

The groups must exist before you can add users to them. When you don't assign a primary group then the useradd command creates a primary group with the same name as the username, like you said. If you want to add the user to additional groups these must exist.

So if you want for example to create a user, assign primary group users and additional groups developers,printer,etc...

If the groups developers and printers don't exist:
Code:
groupadd developers,printers
useradd username -g users -G developers,printers
If the groups already exist then of course you don't have to execute the groupadd command. As far as I know you cannot create a new user and assign him to a secondary group if that group has not been created. So yes, in my opinion you'll need two commands.

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
useradd - question about --non-unique option cygnus-x1 Linux - General 2 02-27-2008 10:57 AM
question about useradd hongxing Linux - Software 4 11-14-2005 07:00 AM
useradd from command line question Strixy Linux - Newbie 4 08-05-2005 06:58 PM
useradd command question hct224 Linux - Newbie 2 06-14-2004 04:47 PM
useradd: unknown group turbofisch Linux - Newbie 4 04-06-2004 06:19 AM


All times are GMT -5. The time now is 02:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration