Linux: How to List All Users

To list all users on Linux, the best general-purpose command is getent passwd. If you only want usernames, run getent passwd | cut -d: -f1. This is usually more complete than reading /etc/passwd directly because getent follows the system's Name Service Switch (NSS) configuration, so it can include accounts supplied by services such as LDAP or other configured identity sources.

List all users with getent

Open a terminal and run:

getent passwd

Each line is a user record. To show only the login names, use:

getent passwd | cut -d: -f1

You can also inspect one known account without scrolling through the full list:

getent passwd alice

The GNU C Library documentation explains that NSS controls how system databases such as passwd are resolved through /etc/nsswitch.conf. See the GNU C Library NSS documentation.

Linux terminal showing the getent passwd command and several user account records
getent passwd shows account records available through the configured user database sources.

List local users from /etc/passwd

If you specifically want accounts stored in the local password database, read /etc/passwd. The file contains one colon-separated record per local account. A typical record includes the username, password placeholder, UID, primary GID, comment field, home directory, and login shell.

For usernames only:

cut -d: -f1 /etc/passwd

The same result can be produced with awk:

awk -F: '{print $1}' /etc/passwd

This list normally includes both human users and service accounts such as root, daemon, or accounts created by installed software.

Linux terminal showing cut extracting usernames from the local /etc/passwd file
The cut command extracts only the first field, which is the username.

View complete local account records

To inspect the complete local file, use less so you can scroll comfortably:

less /etc/passwd

You can also print the file directly:

cat /etc/passwd

On modern Linux systems, the password field commonly contains x. That does not mean the password is stored as plain text in /etc/passwd; password hashes are normally kept separately in /etc/shadow, which has more restrictive permissions. The Linux man-pages project documents the seven fields and this shadow-password behavior in passwd(5).

Linux terminal showing full colon-separated records from the /etc/passwd file
A full /etc/passwd entry contains the username, UID, GID, home directory, shell, and other account fields.

List usernames with Bash compgen

If you are using Bash, compgen can generate username completion candidates:

compgen -u

For a long result, page through it with:

compgen -u | less

Or remove duplicate names and sort the output:

compgen -u | sort -u

compgen is a Bash builtin, so it is less universal than getent for scripts that must work across different shells. The GNU Bash manual documents compgen as part of Bash's programmable completion facilities.

Linux terminal showing compgen -u piped to less with a paged list of usernames
In Bash, compgen -u | less provides a paged username list.

How to show regular users instead of service accounts

There is no single UID cutoff that is correct for every Linux distribution or organization. Many systems reserve lower UIDs for system accounts and assign regular users from a configured minimum, but that policy can vary. If your system uses /etc/login.defs, you can check its configured minimum with:

grep '^UID_MIN' /etc/login.defs

You can also look for accounts with interactive shells as a practical clue:

getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1}'

This is only a heuristic: an account can have an interactive shell without being a normal desktop user, and externally managed users may follow different UID policies.

Save, count, or search the user list

Once you have the list you need, standard shell tools make it easy to reuse:

  • Save usernames: getent passwd | cut -d: -f1 > ~/linux-users.txt
  • Count returned accounts: getent passwd | cut -d: -f1 | wc -l
  • Find one account: getent passwd username

Which method should you use?

CommandBest for
getent passwdBest default; follows configured NSS user sources
cut -d: -f1 /etc/passwdLocal usernames only
cat /etc/passwd or less /etc/passwdInspecting full local account records
compgen -uQuick username listing from Bash

For most administrators and desktop users, start with getent passwd | cut -d: -f1. Use /etc/passwd when you intentionally need only local accounts.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.