How To List Users In Linux
Maybe your like
If you need to check who can log in, verify service accounts, or confirm that a user exists, you need a reliable way to list Linux users from local and directory sources. Every user account on a Linux system is recorded in the /etc/passwd file or in a network directory service such as LDAP.
This guide explains how to list users in Linux using /etc/passwd, getent, and several related commands for everyday user management.
List All Users with /etc/passwd #
Local user information is stored in the /etc/passwd file. Each line represents one user account. To view the file, use cat or less :
Terminalless /etc/passwd
Each line contains seven colon-delimited fields:
| Field | Description |
|---|---|
| Username | Login name |
| Password | x means the hash is in /etc/shadow |
| UID | Numeric user ID |
| GID | Primary group ID |
| GECOS | Full name or comment |
| Home directory | Path to the user’s home |
| Shell | Login shell (e.g., /bin/bash or /usr/sbin/nologin) |
To print only the usernames, use awk or cut :
Terminalawk -F: '{ print $1 }' /etc/passwd Terminalcut -d: -f1 /etc/passwdoutputroot daemon bin sys sync ... sshd vagrant jack anneList All Users with getent #
The getent command queries name service databases configured in /etc/nsswitch.conf, including the passwd database. Unlike reading /etc/passwd directly, getent also returns users from LDAP, NIS, or SSSD if your system uses a network directory.
To list all users:
Terminalgetent passwd
The output format is the same as /etc/passwd. To extract only the usernames:
Terminalgetent passwd | cut -d: -f1Check Whether a User Exists #
To check if a specific user account exists, pass the username directly to getent:
Terminalgetent passwd jack
If the user exists, the command prints the full /etc/passwd entry for that account. If the user does not exist, there is no output and the exit code is 2.
You can use this in a script to test for a user:
Terminalif getent passwd jack > /dev/null 2>&1; then echo "User jack exists" fiTo count the total number of user accounts on the system:
Terminalgetent passwd | wc -lList Only Human Users #
Linux distinguishes between system accounts (created during installation or by packages) and human accounts (created by administrators). The difference is the UID range. On most distributions, human users have a UID between 1000 and 60000, as defined in /etc/login.defs.
To check the UID range on your system:
Terminalgrep -E '^UID_MIN|^UID_MAX' /etc/login.defsoutputUID_MIN 1000 UID_MAX 60000To list only human user accounts:
Terminalgetent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'
To print only the usernames:
Terminalgetent passwd | awk -F: '$3 >= 1000 && $3 <= 60000 { print $1 }'List Users Who Can Log In #
Some accounts have their shell set to /usr/sbin/nologin or /bin/false to prevent interactive login. To list only users with a real login shell:
Terminalgetent passwd | awk -F: '$7 !~ /(nologin|false)$/ { print $1 }'This filters out service accounts and shows only users who can actually open a shell session.
List Logged-In Users #
To see which users are currently logged in, use the who command:
Terminalwhooutputjack pts/0 2026-02-13 09:15 (10.0.2.15) anne pts/1 2026-02-13 10:30 (10.0.2.20)The w command provides more detail, including what each user is running:
TerminalwFor a simple list of logged-in usernames without duplicates:
TerminalusersList Users in a Group #
To see which users belong to a specific group, use getent group followed by the group name:
Terminalgetent group sudooutputsudo:x:27:jack,anneThe last field shows the group members. To list all groups a specific user belongs to, use the groups command:
Terminalgroups jackoutputjack : jack sudo dockerLast Login Information #
The lastlog command shows the most recent login for every account:
TerminallastlogTo filter out accounts that have never logged in, use:
Terminallastlog | grep -v "Never"The last command shows a log of recent login sessions:
Terminallast -n 10This displays the 10 most recent logins, including the terminal, remote host, and session duration.
Troubleshooting #
getent command not foundThe getent tool is part of glibc utilities and is available by default on most Linux distributions. If it is missing, install the standard libc utilities package for your distribution.
getent passwd does not show LDAP or directory usersCheck /etc/nsswitch.conf and verify that passwd includes the correct source (for example files sss or files ldap). If you use SSSD, confirm the service is running and connected.
UID range does not match my distributionThe common human-user range is 1000-60000, but your system can use a different range. Check UID_MIN and UID_MAX in /etc/login.defs, then adjust the awk filter accordingly.
No users appear as logged inThe who, w, and users commands show active sessions only. On servers without interactive logins at that moment, empty output is expected.
Quick Reference #
| Command | Description |
|---|---|
| cat /etc/passwd | Show all local user entries |
| getent passwd | List all users (local + directory) |
| getent passwd jack | Check if user jack exists |
| getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000' | List human users only |
| cut -d: -f1 /etc/passwd | Print usernames only |
| who | Show currently logged-in users |
| w | Logged-in users with activity |
| users | Simple list of logged-in usernames |
| getent group sudo | List members of a group |
| groups jack | Show all groups for a user |
| lastlog | Last login time for all accounts |
| last -n 10 | Recent login history |
FAQ #
What is the difference between system and human users?System users are created during OS installation or by packages and typically have a UID below 1000. Human users are created by administrators and have UIDs in the 1000-60000 range. System accounts usually have /usr/sbin/nologin as their shell.
Why does my system show so many user accounts?Most of those are system accounts created by installed packages. Services like sshd, www-data, and nobody each have their own user for security isolation. To see only human accounts, filter by UID range with getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'.
What is the difference between /etc/passwd and getent?Reading /etc/passwd shows only local accounts. The getent command queries all configured name services, including LDAP, NIS, and SSSD, so it returns both local and network directory users.
How do I list users in a specific group?Run getent group groupname. The last field in the output lists the group members. You can also run groups username to see all groups a particular user belongs to.
How do I find out when a user last logged in?Use lastlog to see the most recent login time for every account, or use last username to see the full login history for a specific user.
Conclusion #
Linux provides several commands for listing and filtering user accounts. Use getent passwd for a complete list, filter by UID range for human users, and use who or last to track login activity.
For managing users, see useradd , userdel , and usermod .
If you have any questions, feel free to leave a comment below.
Tags
linux commandsLinuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
SubscribeUnsubscribe anytime. We respect your inbox.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author pageTag » Where Are Users Stored In Linux
-
How To View System Users In Linux On Ubuntu - DigitalOcean
-
Where Does Linux Store Its Users? - Quora
-
How Linux Stores User Account Information | Beginning Fedora 2
-
Where Are The Passwords Of The Users Located In Linux? - NixCraft
-
6.3.2. Files Controlling User Accounts And Groups
-
Where User Account And Group Information Is Stored
-
How To List Users In Linux {4 Methods Explained} - PhoenixNAP
-
2. How User Information Is Stored On Your System
-
Where Are User Files Stored In Linux? - Systran Box
-
Where And How Are Passwords Stored On Linux
-
Linux Directory Structure: /home And /root Folders
-
Linux Home Directory - Javatpoint
-
How To List Users In Linux | LinuxHostSupport
-
Understanding Linux User Accounts - OES 2018 SP2