According to the useradd manpage, UIDs below 1000 are typically reserved for system accounts.
I’m developing a service that will run as its own user. I know that well-known ports can be found in /etc/services.
Is there a place where I can find out what well-known UIDs are out there? I would like to avoid crashing with someone else’s UID.
getpwent(3)iterates through the password database (usually/etc/passwd, but not necessarily; for example, the system may be in a NIS domain). Any UID known to the system should be represented there.For demonstration, the following shell fragment and C code both should print all known UIDs on the system.
UID 0 is always root and conventionally UID 65534 is
nobody, but you shouldn’t count on that, nor anything else. What UIDs are in use varies by OS, distribution, and even system — for example, many system services on Gentoo allocate UIDs as they are installed. There is no central database of UIDs in use.Also,
/etc/login.defsdefines what “system UIDs” are. On my desktop, it is configured so that UIDs 100-999 are treated as system accounts, and UIDS 1000-60000 are user accounts, but this can easily be changed.If you are writing a service, I would suggest that the package installation be scripted to allocate a UID as needed, and that your software be configurable to use any UID/username.