LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   useradd -u can assign userid and gid at the same time? (https://www.linuxquestions.org/questions/linux-newbie-8/useradd-u-can-assign-userid-and-gid-at-the-same-time-4175572043/)

JockVSJock 02-11-2016 08:43 PM

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?

JJJCR 02-11-2016 10:12 PM

id -g jsmith what is the output?

JockVSJock 02-11-2016 10:26 PM

Code:

id jsmith
id:  jsmith:  No such user


JJJCR 02-12-2016 01:36 AM

try:

groupadd -g 2001 jsmith

then the command you posted above:

useradd -u 1001 jsmith -g 2001 jsmith

JockVSJock 02-12-2016 07:26 AM

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:


suicidaleggroll 02-12-2016 11:19 AM

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.


All times are GMT -5. The time now is 07:38 PM.