To list every user on a Linux machine, run cut -d: -f1 /etc/passwd. For real people only, run awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd. To see who can log in and when they last did, run lslogins -u and lslogins -L -u. On a server joined to Active Directory, add getent passwd and look people up by name.
You have inherited a server, taken over a project, or just need to audit who has access. The first question: who has an account on this machine?
Linux stores user information in a few well-defined places. Once you know where to look, listing users, checking their groups, and managing accounts becomes straightforward.
Tested on Ubuntu Server 24.04.5 LTS in the ReadTheManual lab, 28 Oct 2026, with demo users alice, bob and carol. The screenshots below are from that run, and the audit script is the one printed in this post. The lslogins, users, /etc/login.defs, SSH lock and error screenshots were added from a second 24.04.5 run on 15 Nov 2026, and the Ubuntu 26.04 checks (last, lastb, lastlog, wtmpdb, lastlog2) come from a fresh Ubuntu Server 26.04.1 LTS install the same day.

Quick Reference
| Task | Command |
|---|---|
| List all users | cat /etc/passwd |
| List usernames only | cut -d: -f1 /etc/passwd |
| List human users only | awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd |
| List local users plus any directory users your NSS setup enumerates | getent passwd |
| Check a specific user | id username |
| List groups for a user | groups username |
| List who is logged in | who or w |
| List user accounts with last login | lslogins -u and lslogins -L -u |
| List names of logged-in users on one line | users |
| List recent logins | last (wtmpdb last on Ubuntu 26.04 once installed) |
Understanding /etc/passwd
Every user account on a Linux system has an entry in /etc/passwd. Despite the name, this file does not contain passwords (those are in /etc/shadow, which requires root access).

cat /etc/passwd
Each line follows this format (the full definition is in the passwd(5) manual page):
username:x:UID:GID:comment:home_directory:shell
Example:
eric:x:1000:1000:Eric Lonsdale:/home/eric:/bin/bash
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
The seven fields are:
- Username: the login name
- Password placeholder: always
x(actual hash is in /etc/shadow) - UID: user ID number (0 = root, 1-999 = system accounts, 1000+ = human users)
- GID: primary group ID
- Comment/GECOS: full name or description
- Home directory: the user’s home folder, and where a bare
cdtakes them (more on that in navigating directories with cd, ls and pwd) - Shell: the login shell (
/bin/bashfor interactive users,/usr/sbin/nologinfor service accounts)
List All Usernames
The full /etc/passwd output is noisy. To see just the usernames:
cut -d: -f1 /etc/passwd
This cuts each line at the colon delimiter and prints field 1 (the username).

Alternative using awk:
awk -F: '{print $1}' /etc/passwd
Both produce the same result. Use whichever you remember.
List Human Users Only (Filter System Accounts)
Most Linux systems create dozens of system accounts (www-data, nobody, systemd-network, etc.). To see only real human user accounts, filter by UID 1000 or higher:
awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd
This works because:
- UID 0 = root
- UID 1-999 = system and service accounts
- UID 1000+ = human users created with
useraddoradduser - UID 65534 =
nobody(excluded)
The 1000 is a convention, not a rule. The range that useradd and adduser hand out comes from UID_MIN and UID_MAX in /etc/login.defs, and some systems and images change it. Check it before you trust the filter:
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
On the Ubuntu Server 24.04 lab machine that prints UID_MIN 1000 and UID_MAX 60000, so $3 >= 1000 && $3 < 65534 is a safe filter there. If yours says something else, use your own numbers in place of 1000.

You can also use compgen if you just want a quick list:
compgen -u
This lists every user name the system can enumerate, system accounts included (it is not filtered to UID 1000+). Like getent passwd below, it only includes LDAP or Active Directory users if the directory is set to allow enumeration, which SSSD does not do by default.

List Accounts That Can Log In: lslogins and users
lslogins comes with util-linux, so it is on a stock Ubuntu or Debian server. It reads the same files as the commands above and adds the columns you would otherwise piece together by hand. lslogins -u lists user accounts with their UID, running processes and whether the password is locked (-s does the same for system accounts):
lslogins -u

Give it one user name for the full record: home directory, shell, primary and supplementary groups, last terminal and last login. To get the table form for specific accounts, use -l with a comma-separated list, for example lslogins -l alice,bob.
lslogins alice

For the last login of every account, add -L. On Ubuntu 26.04 the last-login columns stay empty until lastlog2 and libpam-lastlog2 are installed (see below).
lslogins -L -u

The shorter cousin is users. It prints the names of everyone logged in right now on a single line (a name appears once per session). who and w, covered below, show the sessions behind the names.
users
List Users Including LDAP and Active Directory
If your server is joined to Active Directory or uses LDAP for authentication, /etc/passwd only shows local accounts. getent queries the Name Service Switch (NSS) instead, which covers local files plus whatever /etc/nsswitch.conf points at (SSSD, LDAP, winbind). The output format is identical to /etc/passwd:
getent passwd
The catch: on a domain-joined machine this usually still shows only local accounts. SSSD (what realm join sets up on Ubuntu) has enumerate = false by default, so it never lists the whole directory; domain users only appear when looked up by name. Winbind behaves the same way unless enumeration is switched on. Look users up individually instead:
getent passwd eric
getent passwd [email protected] # if fully qualified names are on (realm join's default)
id [email protected]
If the user exists (locally or via LDAP/AD), you will see their entry. If not, no output and a non-zero exit code. Setting enumerate = true for the domain in /etc/sssd/sssd.conf (see enumerate in the sssd.conf manual) makes getent passwd list directory users too, but it is slow and loads the directory on large domains, which is why it is off by default. To list who is in a domain group, getent group "groupname" works without enumeration, though it may only show members SSSD has already resolved.
Check a Specific User's Details
The id command shows everything about a user in one line:
id eric
Output:
uid=1000(eric) gid=1000(eric) groups=1000(eric),4(adm),27(sudo),999(docker)
This tells you:
- Their UID and primary group
- Every group they belong to (including sudo, docker, etc.)
For just the groups in a readable format:
groups eric
Output:
eric : eric adm sudo docker

See Who Is Currently Logged In
To see active sessions:
# Simple list
who
# Detailed (includes load average, idle time, what they are running)
w
Example w output:
14:23:01 up 42 days, 3:15, 2 users, load average: 0.15, 0.10, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
eric pts/0 192.0.2.50 14:20 0.00s 0.03s 0.00s w
deploy pts/1 198.51.100.5 09:15 5:08m 0.01s 0.00s -bash
To see recent login history:
# Last logins
last
# Last 10 logins
last -n 10
# Failed login attempts (requires root; Ubuntu 24.04 and earlier)
sudo lastb

On a freshly built server last may list little more than the boot record, as above: it reads /var/log/wtmp, and an SSH session that runs without a terminal is not recorded there (OpenSSH only writes the login record when it allocates a terminal; see do_exec_pty in OpenSSH's session.c).
Ubuntu 26.04 LTS does not install these tools. On a fresh 26.04.1 server last, lastb and lastlog each answer "command not found". On 24.04 last and lastb come from util-linux and lastlog from login; on 26.04 util-linux no longer contains any of them:

Their replacements are wtmpdb (run it as wtmpdb last) and lastlog2, plus libpam-wtmpdb and libpam-lastlog2 so that logins get recorded. All four are in the universe component for 26.04 (package pages: wtmpdb, lastlog2), so they have to be installed:
sudo apt update
sudo apt install wtmpdb libpam-wtmpdb lastlog2 libpam-lastlog2



The wtmpdb and lastlog2 databases only record logins made after the PAM packages are installed, so history starts at that point. lslogins -L -u reads the same lastlog2 records once those packages are in. For failed SSH logins on any release, the journal works: sudo journalctl -u ssh.service | grep -i 'failed password'.
Security tip: Run last (wtmpdb last on 26.04) regularly to spot unexpected logins. On a server, you should recognise every IP address that connects. If you do not, investigate immediately.
Managing User Accounts
Add a New User
# Interactive (creates home dir, sets shell, prompts for password)
sudo adduser newuser
# Non-interactive (minimal, no home dir by default)
sudo useradd newuser
# Non-interactive with home dir and bash shell
sudo useradd -m -s /bin/bash newuser
sudo passwd newuser

On Ubuntu 24.04, adduser also puts the new account in the users group, as the last two lines above show. useradd does not.
Recommendation: Use adduser on Debian/Ubuntu for interactive setup. Use useradd with flags in scripts for automation.
Add a User to a Group
# Add to sudo group (gives admin privileges)
sudo usermod -aG sudo username
# Add to docker group (run Docker without sudo)
sudo usermod -aG docker username
The -a flag means append. Without it, usermod -G replaces all secondary groups, which can lock users out of sudo. Always use -aG.
Remove a User
# Remove user but keep their home directory
sudo userdel username
# Remove user AND their home directory
sudo userdel -r username
Lock and Unlock Accounts
# Lock the password (password logins fail)
sudo usermod -L username
# Also expire the account, so SSH key logins fail too
sudo usermod -L -e 1 username
# Unlock (and clear the expiry if you set one)
sudo usermod -U -e "" username
# Check status (L in the second field means the password is locked)
sudo passwd -S username

usermod -L on its own only locks the password by putting ! in front of the hash in /etc/shadow. A user with an SSH key in ~/.ssh/authorized_keys can still log in (how SSH keys and authorized_keys work on Ubuntu explains where those keys come from). The usermod manual says to set the expiry date to 1 as well if you want to lock the account rather than just the password, which is what -e 1 does.
Locking is better than deleting when you need to disable access temporarily or preserve the user's files and audit trail.
Useful One-Liners
# Count total users on the system
wc -l /etc/passwd
# Count human users only
awk -F: '$3 >= 1000 && $3 < 65534' /etc/passwd | wc -l
# List users with sudo access
getent group sudo
# List users with shell access (can log in)
grep -v '/nologin\|/false' /etc/passwd | cut -d: -f1
# Find users who have never logged in (Ubuntu 24.04 and earlier; on 26.04 install lastlog2 and run lastlog2)
lastlog | grep "Never logged in"
# User accounts and when they last logged in (24.04; on 26.04 after installing lastlog2 and libpam-lastlog2)
lslogins -L -u
# Check the UID range your system uses for normal users
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
# List all groups on the system
cut -d: -f1 /etc/group
Quick User Audit Script
Here is a script you can drop onto any server for a fast user audit:
#!/bin/bash
echo "=== System: $(hostname) ==="
echo "=== Date: $(date) ==="
echo ""
echo "--- Human Users (UID >= 1000) ---"
awk -F: '$3 >= 1000 && $3 < 65534 {printf " %-20s UID:%-6s Shell:%s\n", $1, $3, $7}' /etc/passwd
echo ""
echo "--- Users With Sudo Access ---"
getent group sudo | cut -d: -f4 | tr ',' '\n' | sed 's/^/ /'
echo ""
echo "--- Currently Logged In ---"
who | sed 's/^/ /'
echo ""
echo "--- Last 5 Logins ---"
last -n 5 | head -5 | sed 's/^/ /'
The last line uses last. On Ubuntu 26.04, change it to wtmpdb last -n 5 after installing wtmpdb, or, once lastlog2 and libpam-lastlog2 are installed, replace it with lslogins -L -u.

Troubleshooting
These are the things that looked wrong in the lab run, with the reason for each.
last shows only the boot record
On a fresh server last lists little more than reboot. It reads /var/log/wtmp, and an SSH session that runs a command without a terminal is not recorded there (screenshot of who, w and last above). A normal interactive SSH login does allocate a terminal and shows up, as in the lslogins -L -u screenshot. Test with ssh -tt user@host exit.
last, lastb or lastlog: command not found
You are on Ubuntu 26.04. They are not installed; see the 26.04 notes under "See Who Is Currently Logged In". Use wtmpdb last and lastlog2 (or lslogins -L -u) once installed.
lastb: cannot open /var/log/btmp: Permission denied
lastb reads the failed-login file, which only root can open, so run it with sudo. An empty result with just a "btmp begins" line means no failed logins were recorded.

getent passwd shows no domain users
That is SSSD with enumerate = false, the default. Look the user up by name (getent passwd name or id name) as described in the Active Directory section above.
A new account is also in the users group
On Ubuntu 24.04, adduser adds the account to the users group (GID 100), as id carol shows in the screenshot under the UID range above. useradd does not. This is a group, not the users command, which lists logged-in sessions.
usermod -L did not stop an SSH login
A locked password does not block a key. Add -e 1 to expire the account, which makes sshd refuse the login, and clear it with usermod -U -e "" to restore it:

usermod -U says it would result in a passwordless account
The account has no password hash to unlock, for example one made with adduser --disabled-password. Set a password with sudo passwd username first, or leave the account as it is.
Where You'll Meet This at Work
On a company estate the user list rarely lives in /etc/passwd. Identity sits in a directory, Active Directory or Microsoft Entra ID, and Linux servers are joined to it. On Ubuntu that join uses SSSD, which Ubuntu's server documentation walks through with the ad provider. On Azure, the AADSSHLoginForLinux extension lets people sign in to a Linux VM with Entra ID and OpenSSH certificates, controlled by the Virtual Machine Administrator Login and Virtual Machine User Login roles.
What maps one to one: id, groups and getent passwd name behave the same on a domain-joined server as in this post, and group membership still decides who gets sudo. What does not: you will not run adduser for staff. Accounts are created, locked and removed in the directory, so offboarding is one change there rather than usermod -L on every server. And, as above, SSSD does not enumerate the directory by default, so getent passwd shows local users and anyone already looked up. A leavers audit starts in Entra ID or AD, and the server check is a lookup by name.
The home version still teaches the half the directory builds on: UIDs, groups, locked accounts and who is logged in right now.
Next Steps
- Check Your Linux Version: know what OS and kernel you are running
- Scripting Fundamentals: automate user management with Bash scripts
- Linux Fundamentals Series: the full series from basics to job-ready
- Secure Linux Servers with Ansible: automate security hardening including user account policies
Frequently Asked Questions
How do I list all users in Linux?
Run cat /etc/passwd to see all local user accounts, or cut -d: -f1 /etc/passwd for just the usernames. getent passwd also queries LDAP or Active Directory sources, but SSSD does not enumerate directory users by default, so on a domain-joined machine look users up by name with getent passwd username or id username.
How do I list only human users in Linux?
Run awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd. This filters by UID 1000 or higher, which is where human user accounts start on most Linux distributions. System and service accounts use UIDs below 1000.
How do I check what groups a user belongs to?
Run id username to see the user's UID, primary group, and all secondary groups. For a simpler output, run groups username which lists just the group names. Checking group membership is important for verifying sudo access, Docker permissions, and file sharing.
How do I see who is currently logged into a Linux server?
Run the w command for a detailed view showing usernames, login times, idle time, and what command they are running. The who command gives a simpler list. For historical login data, use last to see recent logins or sudo lastb to see failed login attempts. Ubuntu 26.04 does not install last or lastb: use lastlog2 or lslogins -L -u after installing lastlog2 and libpam-lastlog2, install wtmpdb to get wtmpdb last, and check the journal for failed SSH logins with sudo journalctl -u ssh.service.
How do I add a user to the sudo group in Linux?
Run sudo usermod -aG sudo username. The -a flag means append (add to the group without removing from other groups) and -G specifies the group. Always use -aG together. Without the -a flag, usermod replaces all secondary groups, which can accidentally remove the user from other important groups.
RTFM Apparel · printed in the UK

ReadTheManual is run, written and curated by Eric Lonsdale.
Eric has over 20 years of professional experience in IT infrastructure, cloud architecture, and cybersecurity, but started with PCs long before that.
He built his first machine from parts bought off tables at the local college campus, hoping they worked. He learned on BBC Micros and Atari units in the early 90s, and has built almost every PC he’s used between 1995 and now.
From helpdesk to infrastructure architect, Eric has worked across enterprise datacentres, Azure environments, and security operations. He’s managed teams, trained engineers, and spent two decades solving the problems this site teaches you to solve.
ReadTheManual exists because Eric believes the best way to learn IT is to build things, break things, and actually read the manual. Every guide on this site runs on infrastructure he owns and maintains.
Enjoyed this guide?
New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.






