Users are numbers with names attached
Every process on Linux carries a user ID, usually written UID, and every file records the UID of its owner. When a process asks to read or write a file, the kernel compares the process UID with the owner recorded on the file. The kernel never compares names. The name you see in your prompt is a label that libraries and tools look up from the number, and that lookup happens in user space, outside the kernel.
UID 0 belongs to the superuser, which is called root. The kernel gives root a special status: root bypasses most of the permission checks that this module describes. Every other UID is an ordinary account. System services usually run under their own UIDs with no login shell, so a flaw in one service cannot quietly change the files that belong to another account. Keeping accounts separate is the basic reason the permission system exists.
Groups follow the same pattern. Each group has a numeric group ID, or GID. A file has one owner and one group. A running process has an effective GID, plus a list of supplementary group IDs. When the kernel checks the group bits of a file, it compares them against all of those values, so membership in a group can grant access even when the group is not your primary group.
The password and group files
On a traditional Linux system, the mapping between names and numbers lives in two plain text files. The file /etc/passwd has one line per account, with seven colon-separated fields: the login name, a placeholder for the password, the UID, the primary GID, a comment, the home directory, and the login shell. The password hash itself is kept in a separate file that only root can read, which is why the second field usually contains only an x.
The file /etc/group has one line per group, with four fields: the group name, a placeholder, the GID, and a comma-separated list of member names. Membership in that list is what makes a group supplementary. The primary group is the one named in the passwd file, and it is the group that new files usually receive. Reading the two files is harmless, and it is the quickest way to see how a name turns into a number.
grep "^root:" /etc/passwdOn most systems the line for root begins with root:x:0:0. That shows the name root maps to UID 0 and GID 0. The two zeros are the reason root is special: the kernel only needs the number to decide what the process may do.
Asking the shell who you are
The id command prints your identity on one line. Each number is followed by its name in parentheses. The format is always the same, which makes the output easy to scan in a script or in a bug report. The fields are uid for your real and effective user, gid for your effective primary group, and groups for every group the process carries.
id
id -u
id -un
id -GThe first command prints the full line. The next three print only parts of it. The -u option prints the numeric UID, -un prints the user name, and -G prints every group number on one line. Scripts usually use the numeric form, because a name can be ambiguous when two directories disagree, while a number is what the kernel actually checks.
The lab has no man pages installed. Use id --help to see the options of this command, and the online pages at man7.org for the system calls that the kernel uses to report identity.
Groups and shared access
Groups let several accounts share files without giving everyone full access. Suppose a team keeps a directory of documents. The owner can be a team lead, the group can be called docs, and the group bits can allow read and write. Each member who is listed in the group file receives those bits without any change to the files themselves. Adding a person to the team becomes one line in /etc/group instead of an edit to every file.
Membership is read when a login session starts. A shell that was already open before a membership change keeps its old group list, and the new group does not appear in that shell until you log in again. This surprises many people, and it is the first thing to check when a new group does not seem to work. The new list is visible in a fresh session with id -Gn.
Only root can change memberships, because only root can edit /etc/group. As an ordinary user you can list your groups and check which group a file belongs to, but you cannot grant yourself a new one. That limit is deliberate, because group membership grants access to files.
What a new file receives
When a process creates a file, the kernel sets the owner of the new file to the effective UID of the process. The group is set to the effective GID, unless the parent directory has the setgid bit set, a case covered in a later unit of this module. For now the rule is simple: your new files belong to you and to your primary group.
touch demo.txt
stat -c "%U %G %u %g" demo.txtThe format string prints the owner name, the group name, the owner UID, and the group GID. Read the four values in order, and check that the names match the ones id printed earlier. If the names match but the numbers look unfamiliar, that is normal, because the numbers are assigned when the account is created.
Why the numbers matter
Because the kernel only uses numbers, a name in a file is never proof of anything by itself. Scripts that compare owner names are fine for reports, but security decisions should compare numeric IDs. The stat command with the %u and %g formats gives you those numbers directly.
Root is the one account the rest of the system treats as trusted with everything. A later unit explains how an ordinary account reaches root through su and sudo. The safe habit, which that unit describes, is to run one command as root when it is needed, rather than to work in a root shell all day. Knowing that the kernel sees only numbers is what makes that habit make sense.
Hands-on: read your own identity
Run id, then run stat on a file you create. Compare the owner and group values with the output of id. Then find the line for root in /etc/passwd and confirm that its UID is 0. The labs at the end of this unit ask you to save these values in files in your workspace, so the checks can confirm each step.