How to List Users in Linux (Local, System, and Network Accounts)
Learn list users in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
12 min read
Learn list users in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What getent Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
Knowing how to list users in Linux is a core diagnostic and auditing skill for system administrators, security analysts, and DevOps engineers. Unlike desktop operating systems that display a simple graphical list of human login profiles, a Linux server maintains dozens of accounts simultaneously—ranging from UID 0 (root) and low-numbered system accounts (sshd, systemd-network, postgres, www-data) to normal human users and centralized domain accounts fetched over LDAP, FreeIPA, or Active Directory.
To list users in Linux, run getent passwd to query all local and centralized network accounts, or run cut -d: -f1 /etc/passwd to output only local usernames. To filter exclusively for normal human login accounts (typically UID 1000 to 60000), run awk -F: '$3 >= 1000 && $3 < 60000 {print $1, $3, $7}' /etc/passwd.
While reading /etc/passwd directly with cat, less, awk, or cut reveals every account defined on the local disk, modern enterprise servers frequently rely on the Name Service Switch (NSS) to authenticate users stored in remote directory services. Because getent passwd queries the exact NSS lookup chain configured in /etc/nsswitch.conf, it is the most reliable command for enumerating both local /etc/passwd users and remote SSSD/LDAP accounts in a single unified stream.
In security audits and compliance reviews (such as CIS Benchmarks, SOC 2, or ISO 27001), simply dumping raw account lines is rarely enough. Administrators must distinguish between unprivileged daemon accounts locked with /usr/sbin/nologin and interactive human accounts with valid login shells (/bin/bash, /bin/zsh) and UIDs at or above UID_MIN (1000). Combining getent passwd with awk, cut, and column lets you extract clean, actionable user inventories in seconds.
What getent Does and When to Use It
Linux resolves account identities through the GNU C Library (glibc) Name Service Switch (NSS) subsystem. When you execute getent passwd, the binary invokes the standard POSIX library functions setpwent(), getpwent(), and endpwent()—or getpwnam() / getpwuid() when specific keys are passed. The C library reads /etc/nsswitch.conf (for example, passwd: files systemd sss) and dynamically loads the corresponding shared libraries (libnss_files.so, libnss_systemd.so, libnss_sss.so) to aggregate user records across local files, systemd dynamic users, and enterprise directory servers.
Each record returned by getent passwd or stored in /etc/passwd consists of seven colon-delimited fields: username:password_placeholder:UID:GID:GECOS_comment:home_directory:login_shell. Linux distributions define the numeric boundary between system accounts and regular human users in /etc/login.defs via the UID_MIN (typically 1000) and UID_MAX (typically 60000) parameters, reserving UID 65534 for the unprivileged nobody overflow account.
Linux enforces discretionary access control (DAC) by evaluating the effective User ID (EUID), effective Group ID (EGID), and supplementary groups against inode permission bits. When getent executes, the Virtual File System (VFS) and active Linux Security Modules (SELinux or AppArmor) validate the caller's privileges before committing changes to disk or account databases.
Availability and Installation Across Linux Distributions
The getent utility is packaged in glibc (libc-bin) across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether getent is installed and inspect which binary path and version your shell resolves:
type -a getent
getent --version 2>/dev/null || man -f getent
# Illustrative output (reviewed against documentation)
getent is /usr/bin/getent
getent (glibc (libc-bin))
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y libc-bin
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y glibc-common
# Arch Linux
sudo pacman -S --noconfirm glibc
# Alpine Linux
sudo apk add --no-cache musl-utils
Command Syntax, Arguments, and Exit Status Codes
getent passwd [USERNAME | UID]
The getent command follows the syntax getent DATABASE [KEY ...], where DATABASE is passwd when querying user accounts. When invoked as getent passwd with no key arguments, it enumerates every user entry available across all configured NSS sources. When one or more keys (either usernames like ubuntu or numeric UIDs like 1000) are supplied, getent looks up only those specific records and prints them in standard /etc/passwd format.
Because both /etc/passwd (mode 0644) and standard NSS user lookups are world-readable by design—so non-root processes like ls -l, ps, and id can translate numeric UIDs into human-readable usernames—listing users does not require sudo or root privileges. However, inspecting password hashes, lock statuses, or expiration dates in /etc/shadow via getent shadow requires superuser privileges.
0— Command completed successfully and all requested user entries were found.1— Missing arguments or invalid database name supplied togetent.2— One or more specified usernames or UIDs were not found in thepasswddatabase.3— Enumeration is not supported on the configured NSS database (for example, when LDAP enumeration is disabled insssd.conf).
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
passwd | DATABASE | Query the user account database across all NSS sources configured in /etc/nsswitch.conf. |
-s | --service SERVICE | Override /etc/nsswitch.conf and query only the specified NSS service (such as files, sss, or systemd). |
-i | --no-idn | Disable Internationalized Domain Name (IDN) encoding during lookup operations. |
-d : | cut delimiter | When piping to cut -d: -f1, split each passwd record on the colon character and extract field 1 (username). |
-F: | awk field separator | When filtering with awk -F:, split records on colons to evaluate $3 (UID) and $7 (login shell). |
-u | compgen -u | Bash built-in completion flag that prints a fast newline-separated list of all known usernames. |
-l | lslogins -u | Util-linux utility flag that displays a formatted table of regular user accounts and last login timestamps. |
--help | --usage | Display built-in command syntax and supported NSS database names. |
Choosing between getent passwd, /etc/passwd, and lslogins depends on your objective. In shell scripts that must verify whether a username or UID exists before provisioning resources, getent passwd "$USER" >/dev/null is the gold standard because it returns exit code 0 if found and 2 if missing, while respecting both local /etc/passwd and network accounts.
When troubleshooting why a domain user appears or fails to appear on a server joined to Active Directory or FreeIPA, passing -s files (getent -s files passwd) vs -s sss (getent -s sss passwd) isolates whether the account record originates from local disk or the SSSD daemon.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. List All Local and Network Users with getent passwd
Run getent passwd to display the complete user table—including UIDs, home directories, and shells—from /etc/passwd and any active NSS directory services.
getent passwd | head -n 6
getent passwd | tail -n 3
# Illustrative output (reviewed against documentation)
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
sshd:x:110:65534::/run/sshd:/usr/sbin/nologin
alex:x:1001:1001:DevOps Engineer:/home/alex:/bin/bash
priya:x:1002:1002:SRE Lead:/home/priya:/bin/zsh
The top lines of the output correspond to foundational system accounts created during OS installation, while the bottom lines show recently added service and human accounts.
2. Extract Only Usernames in Alphabetical Order
When you need a clean list of usernames without UIDs, home paths, or shells, pipe getent passwd (or /etc/passwd) into cut and sort.
getent passwd | cut -d: -f1 | sort | head -n 10
# Illustrative output (reviewed against documentation)
_apt
alex
backup
bin
daemon
dnsmasq
games
gnats
irc
list
cut -d: -f1 splits each line at the colon (:) delimiter and selects only the first column (the login name), which sort then orders lexicographically.
3. List Only Normal Human Users (UID 1000 to 60000)
System administrators almost always want to filter out the 30+ background daemon accounts and view only regular human users created on the machine.
awk -F: '$3 >= 1000 && $3 <= 60000 { printf "%-15s UID=%-6s HOME=%-20s SHELL=%s\n", $1, $3, $6, $7 }' /etc/passwd
# Illustrative output (reviewed against documentation)
ubuntu UID=1000 HOME=/home/ubuntu SHELL=/bin/bash
alex UID=1001 HOME=/home/alex SHELL=/bin/bash
priya UID=1002 HOME=/home/priya SHELL=/bin/zsh
In /etc/passwd, $3 is the numeric UID. Filtering for $3 >= 1000 && $3 <= 60000 excludes both system daemons (< 1000) and the nobody overflow account (65534), printing a clean aligned table of human accounts.
4. List Users with Valid Interactive Login Shells
During a security audit, checking UIDs alone is insufficient because a misconfigured system account below UID 1000 might accidentally have /bin/bash assigned. Filter by the seventh field ($7) to catch every account capable of opening an interactive shell.
getent passwd | awk -F: '$7 !~ /(nologin|false|sync|shutdown|halt)$/ {print $1 ":" $3 ":" $7}' | column -t -s:
# Illustrative output (reviewed against documentation)
root 0 /bin/bash
ubuntu 1000 /bin/bash
alex 1001 /bin/bash
priya 1002 /bin/zsh
postgres 114 /bin/bash
This pipeline excludes non-interactive shells (/usr/sbin/nologin, /bin/false, /bin/sync) and highlights that the postgres service account (UID 114) has an interactive /bin/bash shell.
5. Check If a Specific User or UID Exists
Query getent passwd with one or more usernames or numeric UIDs to inspect specific accounts without grepping the entire file.
getent passwd root 1001
echo "Exit status: $?"
# Illustrative output (reviewed against documentation)
root:x:0:0:root:/root:/bin/bash
alex:x:1001:1001:DevOps Engineer:/home/alex:/bin/bash
Exit status: 0
getent accepts both string usernames (root) and numeric UIDs (1001) in the same invocation and resolves each via NSS.
6. Display a Formatted User Summary Table with lslogins
The lslogins utility from util-linux aggregates data from /etc/passwd, /etc/shadow, /etc/group, and /var/log/wtmp into a human-friendly report.
lslogins -u
# Illustrative output (reviewed against documentation)
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 142 Oct22/08:15 root
1000 ubuntu 4 Oct22/11:40 Ubuntu Cloud User
1001 alex 2 Oct22/14:22 DevOps Engineer
1002 priya 0 Oct21/19:05 SRE Lead
Passing -u instructs lslogins to show only regular user accounts (plus root), along with the count of currently running processes (PROC), password lock flags, and last login timestamp.
Real-World Workflows, Pipelines, and Shell Automation
Dynamic Human User Discovery Using /etc/login.defs Boundaries
Instead of hardcoding 1000 and 60000 in cross-distro audit scripts (since legacy RHEL 6 systems used UID_MIN 500), dynamically parse UID_MIN and UID_MAX from /etc/login.defs and feed them into awk.
#!/usr/bin/env bash
set -euo pipefail
UID_MIN=$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)
UID_MAX=$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)
getent passwd | awk -F: -v min="${UID_MIN:-1000}" -v max="${UID_MAX:-60000}" '$3 >= min && $3 <= max { print $1, $3, $6, $7 }' | column -t
# Illustrative output (reviewed against documentation)
ubuntu 1000 /home/ubuntu /bin/bash
alex 1001 /home/alex /bin/bash
priya 1002 /home/priya /bin/zsh
Extracting UID_MIN and UID_MAX directly from /etc/login.defs with :-1000 and :-60000 fallback defaults makes this script 100% portable across legacy and modern Linux distributions.
Security Audit: Detect Duplicate UIDs and Un authorized UID 0 Accounts
According to CIS Linux Benchmark controls, root must be the only account with UID 0, and no two accounts should share the same numeric UID.
echo "=== Accounts with UID 0 ==="
getent passwd | awk -F: '$3 == 0 {print $1, $3, $7}'
echo "=== Duplicate UIDs ==="
getent passwd | cut -d: -f3 | sort -n | uniq -d | while read -r dup_uid; do
getent passwd | awk -F: -v u="$dup_uid" '$3 == u {print "Duplicate UID " $3 ": " $1}'
done
# Illustrative output (reviewed against documentation)
=== Accounts with UID 0 ===
root 0 /bin/bash
=== Duplicate UIDs ===
The first check flags any backdoor account assigned UID 0. The second check extracts all UIDs, identifies duplicates with uniq -d, and prints any colliding usernames.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding getent inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
Never edit /etc/passwd directly with standard text editors like nano or vim while inspecting user accounts; an accidental syntax error or missing colon can corrupt the file and lock out root. Always use read-only tools (getent, awk, cut, lslogins) to list users, and vipw if manual edits are ever required.
While /etc/passwd must remain world-readable (0644) so user-space utilities can map numeric UIDs to usernames, attackers who gain low-privilege shell access or exploit Local File Inclusion (LFI) vulnerabilities routinely read /etc/passwd to enumerate valid human usernames for SSH brute-force attacks and home directory traversal. Removing unused legacy accounts (userdel -r) and assigning /usr/sbin/nologin to all service accounts reduces your attack surface.
When evaluating which users can actually authenticate to a server, remember that /etc/passwd only shows account definitions and shells—not whether an account is locked in /etc/shadow or holds valid SSH keys in ~/.ssh/authorized_keys. Combine getent passwd with sudo passwd -S -a (to check password lock status) and sudo chage -l during comprehensive access reviews.
GNU/Linux, BSD, and BusyBox Implementation Differences
The getent passwd command is standard across all GNU/Linux distributions (Debian, Ubuntu, RHEL, Fedora, Arch), Alpine Linux (via musl-utils), and FreeBSD/NetBSD. On macOS, neither /etc/passwd nor getent lists normal desktop or server accounts during normal operation because macOS stores accounts in OpenDirectory; on macOS, use dscl . list /Users or dscacheutil -q user instead.
The lslogins utility is part of util-linux and is pre-installed on almost all full Linux servers, but may be omitted in minimal Alpine BusyBox containers. Where lslogins is unavailable, awk -F: ... /etc/passwd and the Bash built-in compgen -u work everywhere without external dependencies.
Troubleshooting Common Errors and Diagnostics
Domain / LDAP users can log in via SSH but do not appear in getent passwd
Root Cause: For performance reasons on large enterprise directories, SSSD disables full user enumeration (enumerate = false in /etc/sssd/sssd.conf) by default.
Resolution: Query the specific domain username directly (getent passwd username), which works even when full enumeration is disabled, or set enumerate = true in /etc/sssd/sssd.conf for small directories.
getent passwd [email protected]
id [email protected]
ls -l shows a raw numeric UID (e.g., 1005) instead of a username
Root Cause: The files are owned by a UID that was deleted from /etc/passwd or belongs to a container/NFS user not present in the local host's NSS database.
Resolution: Verify whether the UID exists with getent passwd 1005 and reassign orphaned files using find /path -uid 1005 -exec chown newuser:newgroup {} +.
getent passwd 1005 || echo "UID 1005 has no passwd entry"
getent: command not found on ultra-minimal container image
Root Cause: Distroless or stripped BusyBox images may omit the getent binary from libc-bin or musl-utils.
Resolution: Read /etc/passwd directly using awk, cut, or pure POSIX shell while IFS=: read loops.
while IFS=: read -r user _ uid gid _ home shell; do
printf "%-15s %s %s
" "$user" "$uid" "$shell"
done < /etc/passwd
Alternatives, Related Commands, and Related Tutorials
- How to Create Users in Linux with the useradd Command — Practical syntax, flags, and examples for
useradd. - How to Remove a User in Linux with the userdel Command — Practical syntax, flags, and examples for
userdel. - How to List Groups in Linux (groups, id, and getent group) — Practical syntax, flags, and examples for
groups. - who Command in Linux: Check Currently Logged-In Users and Sessions — Practical syntax, flags, and examples for
who. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

UNIX and Linux System Administration Handbook, 5th Edition
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/login.defs). Run awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd or lslogins -u to list only human user accounts./etc/passwd only shows user accounts stored locally on that machine's disk. Running getent passwd queries the Name Service Switch (NSS), returning both local /etc/passwd users and network users from LDAP, Active Directory (SSSD), or systemd dynamic users./etc/passwd | wc -l./etc/passwd list all registered accounts on the system regardless of whether they are active. To see only users currently logged in to an active terminal or SSH session, run who, w, or users.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!