Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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...:
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.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.