When managing a Linux server or auditing system security, you often need to see exactly who has access to the machine. Unlike a graphical user interface (GUI) where you simply look at the login screen, finding a comprehensive list of all user accounts in a headless Linux environment requires querying the system’s password file.
In Linux, local user account information is stored in a plain-text configuration file located at /etc/passwd. By reading or parsing this file, you can list every account on the system, including human users and system service accounts.
Method 1: Display the Entire passwd File
The simplest way to see all users is to read the /etc/passwd file using the cat command.
Type the following command and press Enter:cat /etc/passwd
This will output a large block of text. Each line represents one user account and is separated by colons (:). The very first field on each line is the username.
Method 2: Extract Only the Usernames
The output of cat /etc/passwd can be overwhelming because it includes user IDs, group IDs, home directory paths, and shell paths. If you only want a clean list of usernames, you can use the awk or cut command to extract just the first column.
To use cut, type the following command:cut -d: -f1 /etc/passwd
Alternatively, to use awk, type:awk -F':' '{ print $1}' /etc/passwd
Both commands will print a neat, vertical list containing only the account names.
Method 3: Use the compgen Command
If you are using the Bash shell (the default on most Linux distributions), you can use a built-in bash command to list all users.
Type the following command:compgen -u
This command queries the system and prints a simple list of all usernames, achieving the same result as Method 2 without needing to manually parse a text file.
Note: When reviewing these lists, you will notice many accounts you did not create (e.g., sys, daemon, bin, www-data). These are system accounts required by Linux and background services to run securely. Standard human user accounts are usually found at the very bottom of the list.