How to List Users in Linux

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.
The quickest way to list every account is getent passwd, which reads local files and any directory service such as LDAP or SSSD. To see only real human accounts, filter the output by UID (typically 1000 and above). For currently logged-in users, run who or w.
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
:
less /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
:
awk -F: '{ print $1 }' /etc/passwdcut -d: -f1 /etc/passwdroot
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:
getent passwd
The output format is the same as /etc/passwd. To extract only the usernames:
getent passwd | cut -d: -f1Check Whether a User Exists
To check if a specific user account exists, pass the username directly to getent:
getent 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:
if getent passwd jack > /dev/null 2>&1; then
echo "User jack exists"
fiTo count the total number of user accounts on the system:
getent 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:
grep -E '^UID_MIN|^UID_MAX' /etc/login.defsUID_MIN 1000
UID_MAX 60000To list only human user accounts:
getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'
vagrant:x:1000:1000:vagrant,,,:/home/vagrant:/bin/bash
jack:x:1001:1001:,,,:/home/jack:/bin/bash
anne:x:1002:1002:Anne Stone,,,:/home/anne:/bin/bash
patrick:x:1003:1003:Patrick Star,,,:/home/patrick:/usr/sbin/nologinTo print only the usernames:
getent 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:
getent 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:
whojack 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:
wFor a simple list of logged-in usernames without duplicates:
usersList Users in a Group
To see which users belong to a specific group, use getent group followed by the group name:
getent group sudosudo:x:27:jack,anneThe last field shows the group members. To list all groups a specific user belongs to, use the groups
command:
groups jackjack : jack sudo dockerLast Login Information
The lastlog command shows the most recent login for every account:
lastlogTo filter out accounts that have never logged in, use:
lastlog | grep -v "Never"The last command shows a log of recent login sessions:
last -n 10This displays the 10 most recent logins, including the terminal, remote host, and session duration.
Troubleshooting
getent command not found
The 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 users
Check /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 distribution
The 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 in
The 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
. To list groups instead of users, see How to List Groups in Linux
.
If you have any questions, feel free to leave a comment below.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
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 page