tags:

views:

146

answers:

4

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.

A: 

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!

Barry Gallagher
Well, those are the UIDs that are in use on my system, but not all the UIDs that might be out there. For instance, I don't have tomcat installed, but it uses UID 91.
Jim Hunziker
+6  A: 

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.

ephemient
Could you either edit this to mention your comment on Bane's answer above or log that as a new answer? That seems to be the real answer to my question - that the system UIDs are not common across unix/linux distributions, so the problem cannot be solved. I'd like to accept that as the answer.
Jim Hunziker
+2  A: 

This article says that it varies on each flavor of *nix.

Bryan Migliorisi
A: 

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.

JCCyC