2

I'm creating a new user in my system, by calling:

sudo useradd -m -G nas -s /bin/bash alf

which supposedly should create a new user with the same UID and GID. However the passwd file is appended with the line:

alf:x:1004:1007::/home/alf:/bin/bash

Which has 1004 for UID and 1007 for GID. Other users I've created have the same UID and GID, so why is this happening?

1 Answer 1

6

useradd only uses the same UID and GID when either:

  • It won't cause a conflict; or

  • You force it with the -u and -g flags

It will skip over already-in-use IDs. So, I would guess that you have added other users and/or groups since you created those that have matching UID/GID pairs.¹

To get the IDs back in lock-step, you could create the next one with -g and -u flags to give it IDs equal to one past the highest UID and GID yet assigned. Subsequent useradd calls won't fill the gaps back in. They'll just start numbering past the new high-water mark.

There's nothing wrong with having desynchronized UID and GID values. The system will work perfectly fine in that condition. Old-style Unixes generally didn't use a group-per-user scheme, so that the IDs were never synchronized from the start at all.


Footnotes:

  1. You probably did not do this interactively. Many packages add groups, and sometimes users, in order to constrain access to files and other facilities owned by that package. Usually they do this with OS-reserved group IDs below 1000, but not always. When they add a group but not a user, it desynchronizes the two sets of ID values.
1
  • I think that all that matters is that group 1007 is named alf: so that user alf has a group alf. Commented Mar 8, 2015 at 18:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.