LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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, 09:43 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
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, 11:12 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
id -g jsmith what is the output?
 
Old 02-11-2016, 11:26 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301

Original Poster
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
Code:
id jsmith 
id:  jsmith:  No such user
 
Old 02-12-2016, 02:36 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
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, 08:26 AM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301

Original Poster
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
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, 12:19 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137
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


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

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

All times are GMT -5. The time now is 11:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration