Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the well-known UIDs?

Tags:

unix

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.

like image 257
Jim Hunziker Avatar asked Jun 18 '09 15:06

Jim Hunziker


People also ask

What are the UID ranges?

The Linux Standard Base Core Specification specifies that UID values in the range 0 to 99 should be statically allocated by the system, and shall not be created by applications, while UIDs from 100 to 499 should be reserved for dynamic allocation by system administrators and post install scripts.

How do I find my UID for all users?

You can find the UID in the /etc/passwd file, which is the file that also stores all users registered in the system. To view the /etc/passwd file contents, run the cat command on the file, as shown below on the terminal.

What is UID used for?

A unique identifier (UID) is an identifier that marks that particular record as unique from every other record. It allows the record to be referenced in the Summon Index without confusion or unintentional overwriting from other records.

What is group ID and ID?

Normal user IDs are assigned to individuals who use the system interactively. Each user has a unique user ID used to identify the user on the system. Each user can also be assigned one or more group IDs, Group IDs are shared by users in the same group and are not necessarily unique.


1 Answers

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.

like image 122
ephemient Avatar answered Oct 23 '22 06:10

ephemient