Users, Groups & Authentication

/etc/passwd, /etc/shadow, useradd/usermod, and the distinction between su and sudo.

Overview

Every process on Linux runs as some user, and that user decides what the process may touch. Linux has three kinds of account, and knowing which kind to use, and when, is a core sysadmin skill. This chapter covers the three kinds, the files that store them, the commands that change them, and the two ways to borrow more privilege.

Three kinds of user

The kind of an account shows in its user ID (UID), the number the kernel actually checks.

  • Root (UID 0): unrestricted access to everything. Use it sparingly, and always through sudo rather than a direct root session. The golden rule is to *grant the least access needed*.
  • Regular users (UID ≥ 1000): standard login accounts with a home directory and a login shell. These are real humans.
  • Service accounts (UID 1-999): created by packages for daemons such as nginx, postgres and redis. They have no login shell (/sbin/nologin), no password, and no home directory beyond what the service needs.

Key concepts

  • /etc/passwd 7-field format
  • /etc/shadow
  • useradd vs adduser
  • su vs sudo

Interview questions

  • Walk through the /etc/passwd and /etc/shadow file formats. Why are they separate?
  • What is the difference between su and sudo? When would you use each?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio