When we add a new user in linux, it assigns a unique UID to the user which is used to identify users and their access on linux system.
Today we will look how to change the range of minimum and maximum UIDs that can be assigned by useradd command in linux to different users.
Changing Min & Max UID Range
To change this range, we can change UID_MIN and UID_MAX parameters’ value inside the login.defs file.
[root@ngelinux ~]# cat /etc/login.defs | grep -i UID # Min/max values for automatic uid selection in useradd UID_MIN 600 UID_MAX 60000 [root@ngelinux ~]#
In the above file we have changed UID_MIN to 600 and we can see below the UID assigned to the newly created user is 601.
### Add a new user now [root@ngelinux ~]# useradd saket ### Check the UID and GID assigned. [root@ngelinux ~]# tail -1 /etc/passwd saket:x:601:501::/home/saket:/bin/bash [root@ngelinux ~]#
We can see that UID is now assigned from 601, however GID or group id is still assigned starting from 501.
Changing Group ID Range
To change group id minimum and maximum range, we can modify GID parameters inside login.defs file.
[root@ngelinux ~]# cat /etc/login.defs | grep -i gid # Min/max values for automatic gid selection in groupadd GID_MIN 500 GID_MAX 60000 [root@ngelinux ~]#
Hence in case your organization is planning to add few maintenance users, you can increase this number and assign UIDs as per requirement.