3. /etc/passwd

In Linux, usernames are human-readable labels, but the system identifies users with a unique User ID (UID). The mapping between usernames and UIDs is stored in the /etc/passwd file, a critical component for user management.

To view its contents, you can use a simple command:

cat /etc/passwd

This file displays a list of all system users and detailed information about them. Each line represents a single user account.

Dissecting the /etc/passwd Fields

A typical line in this file, often the very first one, looks like this:

root:x:0:0:root:/root:/bin/bash

This entry for the root user contains seven fields separated by colons (:). Understanding the structure of /etc/passwd in Linux is key to managing users. Let's break down each field:

  1. Username: The login name of the user (e.g., root).
  2. Password: A placeholder for the user's encrypted password. The actual password is not stored here for security reasons.
    • An x indicates the encrypted password is in the /etc/shadow file.
    • A * (asterisk) means the account is locked and cannot be used for login.
    • A blank field means the user has no password.
  3. User ID (UID): The unique numerical identifier for the user. The root user always has a UID of 0.
  4. Group ID (GID): The numerical identifier for the user's primary group.
  5. GECOS Field: A comment field that traditionally holds extra information like the user's full name, phone number, or office location. It is comma-delimited.
  6. Home Directory: The absolute path to the user's home directory (e.g., /root).
  7. Default Shell: The user's default command-line interpreter, which is executed upon login (e.g., /bin/bash).

System Users and Special Accounts

When you inspect the /etc/passwd file, you'll notice many accounts that don't belong to human users. These are system accounts used to run specific services or processes with limited permissions, enhancing system security. For example, the daemon user is used for running background daemon processes.

Editing the /etc/passwd File

While you can technically edit the /etc/passwd file directly using a text editor or the vipw command, this is strongly discouraged. Manual edits can easily introduce syntax errors, potentially locking you out of the system or causing instability.

It is always safer and more reliable to use dedicated command-line utilities like useradd, usermod, and userdel to manage user accounts. These tools are designed to modify the file correctly and handle all related configurations.

Sign in to save your learning progress

Sign in

Exercises

To solidify your knowledge, try these hands-on labs. They will help you apply the concepts of user IDs and account management in real-world scenarios and build confidence with Linux user administration.

  1. Manage Linux User Accounts with useradd, usermod, and userdel - Practice the complete lifecycle of user administration, from creating and securing new accounts to modifying and deleting them.
  2. Manage Linux Groups with groupadd, usermod, and groupdel - Gain hands-on experience with core command-line utilities for group administration, including creating new groups and modifying user memberships.
  3. Configure User Accounts and Sudo Privileges in Linux - Learn essential techniques for managing user accounts and sudo privileges to enhance the security of a Linux system.

Quiz

If a user account is locked and cannot be used for login, how is this denoted in the password field of the `/etc/passwd` file? Please answer using only the required character.