How to 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
:
less /etc/passwdEach 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. 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:
getent passwdThe 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:
getent passwd | cut -d: -f1List 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:
sudo lslogins 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 UserThe 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:
lslogins -uThe 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:
lslogins -l jackThe -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:
getent passwd jackIf 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:
if getent passwd jack > /dev/null 2>&1; then
echo "User jack exists"
fiTo count the accounts returned by getent passwd, run:
getent passwd | wc -lList 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:
grep -E '^UID_MIN|^UID_MAX' /etc/login.defsUID_MIN 1000
UID_MAX 60000To list accounts in the default regular-user range, run:
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 }'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:
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:
loginctl list-sessionsOn 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:
whojack 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:
wTo print only the names of logged-in users, run:
usersThe 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:
loginctl list-users 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:
getent group sudosudo:x:27:jack,anneThe 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:
groups jackjack : jack sudo dockerThe 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
lastandlastbfrom util-linux, and removedlastlogfrom the login package. - Ubuntu 24.10 removed
lastlog,last, andlastb. Ubuntu 24.04 LTS still has all three. - Fedora 43 replaced
lastlogwithlastlog2and still shipslastandlastb.
Use lslogins -L to show the last-login records available to util-linux:
lslogins -LTo see the last login for a single account:
lslogins -L -l jackA 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:
lastlog2Its 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:
lastlog2 -u jackThe 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:
wtmpdb lastThe 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
| Command | Description |
|---|---|
cat /etc/passwd | Show all local user entries |
getent passwd | List accounts from sources that support enumeration |
getent passwd jack | Check 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/passwd | Print usernames only |
lslogins | List account details as a table |
lslogins -u | List accounts in the configured regular-user range, plus root |
lslogins -l jack | Show details for a single account |
who | Show currently logged-in users |
w | Logged-in users with activity |
users | Print usernames from login records |
loginctl list-sessions | List current sessions tracked by systemd-logind |
loginctl list-users | List users tracked by systemd-logind, including lingering users |
getent group sudo | Show the group’s GID and explicitly listed members |
groups jack | Show all groups for a user |
lslogins -L | Show the last-login record for each account when available |
lastlog2 | Last login time on Debian 13, Ubuntu 24.10+, Fedora 43+ |
wtmpdb last | Recent login history on Debian 13 and Ubuntu 24.10+ |
lastlog / last -n 10 | Same, 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
.
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 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page