How to List Users in Linux

By 

•

Updated on

•

12 min read

List Users in Linux

If you need to check who has an account, verify service accounts, or confirm that a user exists, start with the system’s configured account sources. These can include the local /etc/passwd file and a network directory such as LDAP.

Start with getent passwd to list accounts from sources that support enumeration. To find regular user accounts, filter the output by UID or run lslogins -u. For current login sessions, run w or, on systems with systemd-logind, loginctl list-sessions.

This guide explains how to list users in Linux using /etc/passwd, getent, lslogins, 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 :

Terminal
less /etc/passwd

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. Its output can include users from sources such as LDAP, NIS, or SSSD if they provide a list of accounts.

To list the accounts available through enumeration, run:

Terminal
getent passwd

The output format is the same as /etc/passwd. SSSD disables enumeration by default, so a directory user can be absent from this list even when getent passwd username finds the account. To extract only the usernames from the list:

Terminal
getent passwd | cut -d: -f1

List Users with lslogins

The lslogins command comes from util-linux and prints account details in a formatted table. It can filter by the configured UID ranges for regular and system accounts.

Run it without arguments to list accounts. To include PWD-LOCK and PWD-DENY values from protected shadow records, run it with sudo:

Terminal
sudo lslogins
output
  UID USER             PROC PWD-LOCK PWD-DENY  LAST-LOGIN GECOS
    0 root              119        1        0             Super User
    1 bin                 0        0        0             bin
    2 daemon              0        0        0             daemon
...
 1000 linuxize            4        0        0       21:39 Linuxize
 1001 jack                0        1        0
 1002 anne                0        1        0             Anne Stone
65534 nobody              0        0        0             Kernel Overflow User

The PROC column counts the processes each account is running. For jack and anne, PWD-LOCK=1 indicates a locked password, and the blank LAST-LOGIN field means lslogins found no login record.

An unusable password field such as * can still show PWD-DENY=0. An account with a locked password may still be able to use an SSH key. To set a password for a local account, use passwd .

To restrict the list to regular user accounts, use the -u option:

Terminal
lslogins -u

The default regular-user range is UID 1000 to 60000. The output can also include root. The -s option selects the system range, with UIDs 101 to 999 by default. lslogins uses the ranges in /etc/login.defs when they are configured there.

To look up a single account, pass the username to -l:

Terminal
lslogins -l jack

The -a option adds the last password change and account expiry dates, -G adds supplementary group membership, and --output-all prints every available column. To list the columns you can select with -o, run lslogins --help. The available columns are listed at the end of the output.

Check Whether a User Exists

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

Terminal
getent passwd jack

If the lookup succeeds, the command prints the account in /etc/passwd format. If the lookup finds no match, 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 accounts returned by getent passwd, run:

Terminal
getent passwd | wc -l

List Only Human Users

The UID range is a useful shortcut for finding regular user accounts. On most distributions, the default range in /etc/login.defs is 1000 to 60000. Debian, Ubuntu, and RHEL 7 and later start regular users at 1000 by default. RHEL 6 started at 500. Check your system’s range before putting it in a script.

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 accounts in the default regular-user range, run:

Terminal
getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'
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 }'

Use the awk filter when you want plain text or need to choose the exact range. For a formatted table based on your system’s UID settings, use lslogins -u.

List Users Who Can Log In

Some accounts use a shell such as /bin/false to prevent an interactive shell session. The path to nologin varies by distribution. To exclude accounts that use either shell, match the filename at the end of the path:

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

This is a shell check. Service accounts with other shells still appear, and account expiry, PAM rules, or SSH settings can block a user with a valid shell.

List Logged-In Users

On systems running systemd-logind, use loginctl list-sessions to see current sessions. It shows a row per session, with the seat or terminal when available:

Terminal
loginctl list-sessions

On Ubuntu 26.04, the Rust coreutils version of who can print numeric UIDs and miss SSH sessions. The Rust version of users can also omit sessions. On affected systems, use loginctl list-sessions, w, or the GNU version of who, available as gnuwho.

The who command shows login records on many Linux systems:

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)

Here, jack and anne each have a login record on a separate terminal (pts/0 and pts/1).

The w command provides more detail, including what each user is running:

Terminal
w

To print only the names of logged-in users, run:

Terminal
users

The command can repeat a username when it finds multiple login records for that user.

To see one row per user tracked by systemd-logind, run:

Terminal
loginctl list-users
output
 UID USER     LINGER STATE
1000 linuxize no     active

1 users listed.

The STATE column shows linuxize as active. A user with lingering enabled can also appear here after logging out. Use loginctl list-sessions to check for open sessions.

List Users in a Group

To see the members explicitly listed for a group, use getent group followed by the group name:

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

The last field lists jack and anne. Users with sudo as their primary group can be absent from that field. To find primary members, compare the group’s GID (27 here) with the fourth field of the account records from getent passwd.

To list all groups a specific user belongs to, use the groups command:

Terminal
groups jack
output
jack : jack sudo docker

The output lists jack’s primary group, jack, along with the supplementary groups sudo and docker.

Last Login Information

This is the part of user listing that changed the most recently, so the right command depends on how new your system is. The classic lastlog and last commands read /var/log/lastlog and /var/log/wtmp, and neither file format can store timestamps past 2038. Rather than change the formats, the projects behind them dropped the tools:

  • Debian 13 (Trixie) removed last and lastb from util-linux, and removed lastlog from the login package.
  • Ubuntu 24.10 removed lastlog, last, and lastb. Ubuntu 24.04 LTS still has all three.
  • Fedora 43 replaced lastlog with lastlog2 and still ships last and lastb.

Use lslogins -L to show the last-login records available to util-linux:

Terminal
lslogins -L

To see the last login for a single account:

Terminal
lslogins -L -l jack

A blank LAST-LOGIN field means lslogins found no record. A system with missing or unpopulated login logs can show blanks for users who have signed in. A command such as ssh server uptime does not request a terminal by default, and may be missing from login history. If the SSH service runs pam_lastlog2, it can update the last-login record even without a terminal.

On Debian 13 and Ubuntu 24.10 and later, install lastlog2 and libpam-lastlog2 to add the command and the PAM module that records new logins. Fedora 43 provides these in util-linux and liblastlog2. To read the recorded logins, run:

Terminal
lastlog2

Its options mirror the old tool. Use -u for one account, -b to show records older than a number of days, and -t to show only records more recent than that:

Terminal
lastlog2 -u jack

The replacement for last is wtmpdb, which stores sessions in a SQLite database at /var/log/wtmp.db. Install the wtmpdb and libpam-wtmpdb packages, then run:

Terminal
wtmpdb last

The wtmpdb package also installs last as a symbolic link to wtmpdb. After the install, you can type last as before and get the same output.

On Ubuntu 24.04 LTS, RHEL 10, and other systems that still ship the original tools, lastlog and last -n 10 continue to work as before. For a fuller treatment of session history, see the last command .

Quick Reference

CommandDescription
cat /etc/passwdShow all local user entries
getent passwdList accounts from sources that support enumeration
getent passwd jackCheck if user jack exists
getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'List accounts in the default regular-user UID range
cut -d: -f1 /etc/passwdPrint usernames only
lsloginsList account details as a table
lslogins -uList accounts in the configured regular-user range, plus root
lslogins -l jackShow details for a single account
whoShow currently logged-in users
wLogged-in users with activity
usersPrint usernames from login records
loginctl list-sessionsList current sessions tracked by systemd-logind
loginctl list-usersList users tracked by systemd-logind, including lingering users
getent group sudoShow the group’s GID and explicitly listed members
groups jackShow all groups for a user
lslogins -LShow the last-login record for each account when available
lastlog2Last login time on Debian 13, Ubuntu 24.10+, Fedora 43+
wtmpdb lastRecent login history on Debian 13 and Ubuntu 24.10+
lastlog / last -n 10Same, on Ubuntu 24.04 LTS, RHEL 10, and older systems

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
First try getent passwd username with a known directory account. If the lookup works, your directory source may have enumeration disabled. That is the default in SSSD. If the lookup also fails, check the passwd sources in /etc/nsswitch.conf and verify the directory connection.

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
Empty output can mean that there are no current sessions or that the command could not find the login records. On systems with systemd-logind, also check loginctl list-sessions.

who prints a UID or misses SSH sessions
If you see this on Ubuntu 26.04 with Rust coreutils, try w, loginctl list-sessions, or gnuwho.

lastlog: command not found
Debian 13, Ubuntu 24.10 and later, and Fedora 43 and later removed lastlog because its log format is not safe past 2038. Use lslogins -L, or install the lastlog2 package and run lastlog2.

last: command not found
The same change removed last and lastb from util-linux on Debian 13 and current Ubuntu releases. Install the wtmpdb and libpam-wtmpdb packages so that PAM records new sessions, then run wtmpdb last instead. The package also brings back last as a link to wtmpdb.

lastlog2 shows no logins after installing it
The plain lastlog2 command displays records already in the database. Install libpam-lastlog2 on Debian or Ubuntu, or check for liblastlog2 on Fedora 43. Make sure the login service uses pam_lastlog2, then log in again. The sudo lastlog2 -i /var/log/lastlog command can import old records and overwrite existing entries. Back up your current database before importing.

FAQ

What is the difference between system and human users?
System accounts are created for the OS and its services. On many distributions, they typically have UIDs below 1000, and regular user accounts default to UIDs from 1000 to 60000. The ranges are configurable and give you a starting point for filtering accounts.

Why does my system show so many user accounts?
Installed packages often create accounts for individual services so that each service can run with its own permissions. To narrow the list to the usual regular-user UID range, run getent passwd | awk -F: '$3 >= 1000 && $3 <= 60000'.

What is the difference between /etc/passwd and getent?
Reading /etc/passwd shows local accounts. getent passwd can also list directory accounts when the directory source supports enumeration. Use getent passwd username to look up a specific account.

How do I list users in a specific group?
Run getent group groupname to see the group’s GID and explicitly listed members. To find primary members, look for the same GID in the fourth field of getent passwd records. You can also run groups username to check one user’s memberships.

How do I find out when a user last logged in?
Run lslogins -L -l username to check the record for one account. On systems that record logins with pam_lastlog2, you can query that database directly with lastlog2 -u username.

How do I list users on Ubuntu or Debian specifically?
Run getent passwd to list available account records, or lslogins -u to filter by the regular-user UID range. For current sessions on Ubuntu 26.04, use loginctl list-sessions on systems with systemd-logind.

Conclusion

When you are checking a particular user, start with getent passwd username. Use lslogins -L -l username if you also need that account’s recorded last login.

For managing users, see useradd , userdel , and usermod . To list groups instead of users, see How to List Groups in Linux .

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 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page