Jim Hunziker
Jim Hunziker

Reputation: 15420

What are the well-known UIDs?

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.

Upvotes: 5

Views: 10426

Answers (4)

geekasylum
geekasylum

Reputation: 106

I know this is an old post, but since I am here in 2017, still trying to answer a similar question I thought this additional information was relevant for anyone else in the same position.

The concept of "Well known UIDs" stems back to the early days of unix, before there were multitudes of distributions and unix variants. "Well known" UIDs were considered to be those for system users like adm, daemon, lp, sync, operator, news, mail etc, and were standard across all the various systems in order to avoid uid clashes. These users are still present in modern unix-like operating systems.

Standardising uid's across an organisation is the key to avoiding these problems. As was pointed out in a comment above, these days any uid you choose is likely to be in use 'somewhere', so the best a sysadmin can aim for is to ensure that uid's are standard across all the systems that they maintain, then allocating a new uid for an application becomes simple.

To that end, for many years I have found the post linked below invaluable, and sadly there are not a lot of similar posts on the topic, and what's out there is hard to find.

UNIX/Linux: Analyzing user/group UID/GID conflicts

If you search that blog under the 'uid' tag there are other relevant posts, including a script to automate the process of standardising uid's across multiple hosts under Linux.

This User ID Definition is also an invaluable resource.

The short answer is, that it doesn't really matter which uid's you use, as long as they are unique and standard across your organisation, to avoid clashes.

Upvotes: 9

JCCyC
JCCyC

Reputation: 16622

In Linux, that is configured in /etc/login.defs. Sometimes, when I install a Debian-based system, I change the "uid start" option (I forget its name, I'm not on Linux now) from 1000 to 500 for consistency with the other, Red Hat-y machines.

man login.defs should give you all the info you want.

Upvotes: 0

ephemient
ephemient

Reputation: 205014

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.

$ getent passwd | cut -d: -f3
#include <pwd.h>
#include <stdio.h>
int main() {
    struct passwd *pw;
    while ((pw = getpwent()))
        printf("%d\n", pw->pw_uid);
}

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.defs defines 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.

Upvotes: 9

Barry Gallagher
Barry Gallagher

Reputation: 6246

I'm not sure such a list exists. How about just noting that UID's are in use through the /etc/passwd file, /etc/shadow file, and the NIS global user list, noting what ones are in use? Then use one that isn't!

Upvotes: 0

Related Questions