A quick question about UID assignement

Issues related to applications and software problems and general support
Post Reply
ashlife
Posts: 2
Joined: 2024/01/21 12:55:52

A quick question about UID assignement

Post by ashlife » 2024/01/21 13:20:13

I know login.defs is responsible for the min/max uid limits and subsequent uids are assigned based on the last uid assigned at the /etc/passwd file(eg: useradd john would have uid 1000, useradd sam would have uid 1001.)
Now when I entered users with an explicit uid as 2000, and the next user with uid 1500, you would expect the consecutive user would be assigned 1500. But why does the system assign 2001?
When I mess with login.defs file to set the max uid level to 2000, and then add an user. The system assigns an automatic uid value of 1001. When I change the login.defs back to default and then add an user, the user was assigned 2002.
Why wasn't 1501 assigned when the maxlevels were changed to 2000?
Why does it behave like this? I couldn't find articles on this maybe because I don't know what exactly to look for. Thank you in advance for any answers.
centos 1000 (auto)
user1 2000 (useradd -u)
user2 1500 (useradd -u)
user3 2001 (automatic uid)
(after changing max level to 2000)
user4 1001 (automatic uid)
(after changing back the max level back to 60000)
user5 2002 (automatic uid)

User avatar
TrevorH
Site Admin
Posts: 33224
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: A quick question about UID assignement

Post by TrevorH » 2024/01/21 16:38:26

Without reading the code, that all makes sense to me. It picks the next usable uid above the current high water mark (HWM: 2000 so next available is 2001). But you told it that the max should be 2000 and the next available would be 2002 so it can't use that so wrapped round and started from the beginning again (i.e next highest available after MIN). It's not going to iterate through the entire lot working out where the highest gap is so first available above MIN makes sense.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

ashlife
Posts: 2
Joined: 2024/01/21 12:55:52

Re: A quick question about UID assignement

Post by ashlife » 2024/01/22 12:23:44

TrevorH wrote:
2024/01/21 16:38:26
It's not going to iterate through the entire lot working out where the highest gap is so first available above MIN makes sense.
Thank you for your response. I couldn't find a single answer on this question anywhere, and this helped a lot. Have a good day!

Post Reply