How to List Users in Linux

By 

Updated on

6 min read

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 :

Terminal
less /etc/passwd
linux etc passwd list users

Each line contains seven colon-delimited fields:

FieldDescription
UsernameLogin name
Passwordx means the hash is in /etc/shadow
UIDNumeric user ID
GIDPrimary group ID
GECOSFull name or comment
Home directoryPath to the user’s home
ShellLogin shell (e.g., /bin/bash or /usr/sbin/nologin)

To print only the usernames, use awk or cut :

Terminal
awk -F: '{ print $1 }' /etc/passwd
Terminal
cut -d: -f1 /etc/passwd
output
root
daemon
bin
sys
sync
...
sshd
vagrant
jack
anne

List 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:

Terminal
getent passwd
linux getent list users

The output format is the same as /etc/passwd. To extract only the usernames:

Terminal
getent passwd | cut -d: -f1

Check Whether a User Exists

To check if a specific user account exists, pass the username directly to getent:

Terminal
getent passwd jack
Check whether a user exists in the Linux system

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:

Terminal
if getent passwd jack > /dev/null 2>&1; then
    echo "User jack exists"
fi

To count the total number of user accounts on the system:

Terminal
getent passwd | wc -l

List 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:

Terminal
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
output
UID_MIN          1000
UID_MAX         60000

To list only human user accounts:

Terminal
getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'
Linux System and Normal Users
output
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/nologin

To print only the usernames:

Terminal
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:

Terminal
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:

Terminal
who
output
jack     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:

Terminal
w

For a simple list of logged-in usernames without duplicates:

Terminal
users

List Users in a Group

To see which users belong to a specific group, use getent group followed by the group name:

Terminal
getent group sudo
output
sudo:x:27:jack,anne

The last field shows the group members. To list all groups a specific user belongs to, use the groups command:

Terminal
groups jack
output
jack : jack sudo docker

Last Login Information

The lastlog command shows the most recent login for every account:

Terminal
lastlog

To filter out accounts that have never logged in, use:

Terminal
lastlog | grep -v "Never"

The last command shows a log of recent login sessions:

Terminal
last -n 10

This 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

CommandDescription
cat /etc/passwdShow all local user entries
getent passwdList all users (local + directory)
getent passwd jackCheck if user jack exists
getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'List human users only
cut -d: -f1 /etc/passwdPrint usernames only
whoShow currently logged-in users
wLogged-in users with activity
usersSimple list of logged-in usernames
getent group sudoList members of a group
groups jackShow all groups for a user
lastlogLast login time for all accounts
last -n 10Recent 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.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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