When running useradd in RHEL 6, the uid & gid do not match when the specified uid is less than 500

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 6

Issue

  • When running useradd in RHEL 6, the resulting uid & gid do not match when the specified uid is less than 500
[root@localhost ~]# useradd -u 104 patrol2
[root@localhost ~]# id patrol2
uid=104(patrol2) gid=501(patrol2) groups=501(patrol2)

Resolution

  • Unless the "-r" option is given, useradd will allocate the next available gid of a normal group. If the option is given then useradd will attempt to create the group with a matching GID.
[root@localhost ~]# useradd -r -u 104 patrol2
[root@localhost ~]# id patrol2
uid=104(patrol2) gid=104(patrol2) groups=104(patrol2)

Diagnostic Steps

RHEL 5

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# useradd -u 104 patrol2
[root@localhost ~]# id patrol2
uid=104(patrol2) gid=104(patrol2) groups=104(patrol2) 

RHEL 6

Linux localhost.localdomain 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Feb 20 12:17:37 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# useradd -u 104 patrol2
[root@localhost ~]# id patrol2
uid=104(patrol2) gid=501(patrol2) groups=501(patrol2)

[root@localhost ~]# useradd -r -u 104 patrol2
[root@localhost ~]# id patrol2
uid=104(patrol2) gid=104(patrol2) groups=104(patrol2)

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.