LinuxQuestions.org
Visit Jeremy's Blog.
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 02-11-2016, 08:43 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
useradd -u can assign userid and gid at the same time?


Found this example stating you can add a user with a uid and gid at the same time. Both uid and gid are different. I then tried it with the same number for user and group.

Example:

Code:
useradd -u 1001 jsmith -g 2001 jsmith 
useradd: group '2001' does not exit 

useradd -u 9999 mberenyi -g 9999 mberenyi 
useradd:  group '9999' does not exit
I can't get either to work. Even though the example I found is saying it will work.

Is there a way to add a user by uid and gid with useradd? Or is this incorrect?
 
Old 02-11-2016, 10:12 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,161

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
id -g jsmith what is the output?
 
Old 02-11-2016, 10:26 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Code:
id jsmith 
id:  jsmith:  No such user
 
Old 02-12-2016, 01:36 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,161

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
try:

groupadd -g 2001 jsmith

then the command you posted above:

useradd -u 1001 jsmith -g 2001 jsmith
 
1 members found this post helpful.
Old 02-12-2016, 07:26 AM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
That worked.

The example that I'm working from can be found here, which I don't think is correct is here:

http://www.tecmint.com/add-users-in-linux/

Seems like you have to create the group first and then modify the gid with what you posted.

Here is the example:

Code:
groupadd -g 2112 glee 

useradd -u 2112 -g 2112 glee

grep -i glee --color /etc/passwd 
glee:x:2112:2112::/home/glee:/bin/bash 

grep -i glee --color /etc/group
glee:x:2112:
 
Old 02-12-2016, 11:19 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
See the man page for useradd:
Code:
       -g, --gid GROUP
           The group name or number of the user's initial login group. The
           group name must exist. A group number must refer to an already
           existing group.
If the tutorial says otherwise, it's wrong. Always consult the man page when a flag isn't working as you expect.
 
  


Reply

Tags
gid, uid, useradd



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
difference between gid and effective gid zahidul Linux - Newbie 1 10-01-2008 10:44 AM
Change UserID rickh LQ Suggestions & Feedback 6 05-07-2007 09:21 AM
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 01:36 AM
userid expiry ust Linux - Software 1 09-25-2003 05:14 AM
useradd an all numeric userid cpaluch Linux - General 6 12-26-2001 05:12 PM

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

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