Overview
Linux identity is split across two files by design: /etc/passwd holds the world-readable account information, username, UID, primary GID, home directory, login shell, that ordinary tools need to resolve constantly, while /etc/shadow holds the actual password hash and is readable only by root. Every permission and ownership check the kernel performs operates on the numeric UID, never the username, which is why UID 0 is what "root" actually means. Elevated privilege for specific commands is granted through sudoers, whose rules follow a consistent who/where/as-whom/what structure, and whose NOPASSWD tag removes the re-authentication prompt for whichever commands it's attached to.
Quick Reference
| File | Readable by | Holds |
|---|---|---|
/etc/passwd | Everyone | Username, UID, GID, home directory, shell |
/etc/shadow | Root only | Encrypted password hash, password aging data |
/etc/group | Everyone | Group names, GIDs, and supplementary members |
/etc/sudoers | Root only (edit via visudo) | Who can run what, as whom, on which hosts |
Syntax
useradd -m -s /bin/bash -G deploy alice # create a user, home dir, shell, group
usermod -aG docker alice # add to a supplementary group
id alice # show UID, GID, and group membershipsExamples
# /etc/sudoers - who / where = (as whom) what
# ray may run /bin/kill on host rushmore without a password prompt.
ray rushmore = NOPASSWD: /bin/killEdit sudoers only with visudo
visudo validates the file's syntax before saving and locks it against concurrent edits. Editing /etc/sudoers directly with a normal editor risks a syntax error that can lock every user, including root via sudo, out of privileged commands until it's fixed from a root shell or rescue mode.
Visual Diagram
Common Mistakes
- Assuming renaming a username changes its privileges; only the UID it maps to determines that, and two usernames can share UID 0.
- Editing
/etc/sudoersdirectly instead of viavisudo, risking a syntax error that breaks sudo for everyone. - Applying
NOPASSWDbroadly (e.g., toALLcommands) instead of scoping it to the specific, narrow commands that genuinely need it. - Adding a user to a group with
usermod -G(without-a) and unintentionally replacing all of their existing supplementary group memberships instead of adding to them.
Performance
- UID/GID-based permission checks are simple integer comparisons the kernel performs on every file access; the cost is negligible next to the I/O itself.
- Very large
/etc/passwd//etc/groupfiles (thousands of local accounts) can slow down tools that do a full linear scan; centralized directory services (LDAP, SSSD) are the standard fix at that scale, not a larger flat file.
Best Practices
- Always edit
/etc/sudoers(or files under/etc/sudoers.d/) withvisudo, never a plain text editor. - Scope
NOPASSWDand any sudo grant to the specific commands actually needed, not a blanketALL. - Use
usermod -aG(append), not-Galone, when adding a user to an additional group. - Prefer supplementary groups and sudo rules over sharing a UID or handing out root's actual password for day-to-day privileged access.