Ubuntu List Users: Audit Accounts, Sudo & SSH Keys Safely
Copy-paste commands to list real users on Ubuntu 24.04/26.04, audit sudo access, check active SSH sessions and authorized_keys, and manage deploy users.
· 7 min read
On this page
Knowing how to run an Ubuntu list users audit is one of those core Linux habits you end up reaching for constantly — whether you're taking over an older production VPS from a contractor, untangling Permission denied errors between PHP-FPM and Caddy, or doing a quick quarterly security check to verify who actually has sudo and SSH access on your server.
The annoying part about just running cat /etc/passwd on Ubuntu 24.04 or 26.04 is that it dumps 40+ system service accounts (daemon, systemd-network, www-data, _apt, messagebus, caddy, postgres) mixed right in with real human login accounts. And listing usernames alone only tells you half the story — in real production security, you also need to know which accounts have an interactive login shell, which ones can escalate to root via sudo, which ones hold SSH keys in authorized_keys, which ones own scheduled cron jobs or systemd services, and who is logged in right now.
This is the complete, copy-pasteable Ubuntu 24.04/26.04 user-auditing handbook I actually use on production servers.
(Hardening a brand-new server from scratch? Follow our full Ubuntu 24.04 server setup checklist.)
Understanding /etc/passwd Fields (So You Can Read It at a Glance)
Every local user on Ubuntu has one colon-delimited line in /etc/passwd with seven fields:
crab:x:1000:1000::/home/crab:/bin/bash
In order:
- Username:
crab - Password placeholder:
x(actual hashes live in root-only/etc/shadow) - UID (User ID):
0isroot,1–999are system/service accounts,1000+are normal human/login accounts (exceptnobodyat65534) - GID (Primary Group ID):
1000 - GECOS (Comment/Full Name): optional
- Home directory:
/home/crab - Login shell:
/bin/bash(interactive) vs/usr/sbin/nologinor/bin/false(non-interactive service account)
Once you know those seven fields, every awk, cut, and getent one-liner below makes instant sense instead of feeling like arcane Bash magic.
1. Ubuntu List Users: Show Only Real Human Accounts
Ubuntu assigns regular login users UIDs starting at 1000 (defined in /etc/login.defs under UID_MIN). Filter /etc/passwd with awk to see only real human accounts, their UID, home directory, and shell:
awk -F: '$3 >= 1000 && $1 != "nobody" {printf "%-16s UID=%-6s HOME=%-22s SHELL=%s\n", $1, $3, $6, $7}' /etc/passwd
On a clean production VPS, you want to see a very short list — ideally just your single deploy/admin user:
crab UID=1000 HOME=/home/crab SHELL=/bin/bash
If you see an account you don't recognize (ubuntu, an old teammate's name, or a suspicious generic username like support or backup with /bin/bash), investigate it immediately before moving on. Also check for any second UID 0 account — in Linux, UID 0 is root regardless of the username:
awk -F: '$3 == 0 {print $1}' /etc/passwd
If that prints anything other than root, treat the box as compromised and rebuild from clean backups.
2. List Every User (Including System & Service Accounts)
To see every account on the machine — including service accounts like caddy, postgres, mysql, redis, and www-data — prefer getent passwd over cat /etc/passwd. getent queries Ubuntu's Name Service Switch (/etc/nsswitch.conf), so it works identically on plain VPSes and on enterprise boxes using LDAP or SSSD:
getent passwd | cut -d: -f1 | sort
Want to list only accounts that can actually log in interactively (excluding /usr/sbin/nologin, /bin/false, and /bin/sync)?
getent passwd | awk -F: '$7 !~ /(nologin|false|sync)$/ {printf "%-16s UID=%-6s SHELL=%s\n", $1, $3, $7}'
On a hardened Ubuntu 24.04/26.04 server, this should normally return only root and your deploy user (crab). If a service account like www-data or postgres ever shows /bin/bash here, ask why!
3. Audit sudo Privileges (And Catch Hidden sudoers.d Rules)
Listing users isn't a real security audit until you check who can run commands as root. First, check members of the sudo and admin groups:
getent group sudo
Here is the gotcha a lot of engineers forget: a user does NOT need to be in the sudo group to have root privileges. Cloud-init, control panels, and past sysadmins frequently drop files into /etc/sudoers.d/ granting individual users NOPASSWD: ALL or scoped commands. Always inspect both /etc/sudoers and /etc/sudoers.d/:
sudo ls -la /etc/sudoers.d/
sudo grep -rnvE '^\s*(#|$)' /etc/sudoers.d/
For any specific user, you can also ask sudo directly what they're allowed to run:
sudo -l -U crab
4. Check Active Logins, Recent SSH History, and Password Status
Need to see who is connected to your server right this second, and who logged in over the past week?
# Active sessions with idle time and current command
w
# Last 15 successful logins (who, from which IP, when)
last -n 15
# Last login timestamp for every account
lastlog | grep -v "Never logged in"
You should also check which accounts have an active password hash vs. locked/passwordless SSH-only status:
sudo awk -F: '($2 != "*" && $2 != "!" && $2 != "!!") {print $1 " has a password set"}' /etc/shadow
On an SSH-key-only production server, having zero accounts with password login enabled (combined with PasswordAuthentication no in /etc/ssh/sshd_config.d/00-hardening.conf) eliminates password-guessing attacks completely.
5. Audit Every authorized_keys File Across the Entire Server
This is the check that catches 90% of forgotten access on older VPSes: an ex-contractor's laptop key sitting silently inside /root/.ssh/authorized_keys or /home/ubuntu/.ssh/authorized_keys two years after they left the project.
Find every authorized_keys file and list each key's type and comment:
sudo find /root /home -maxdepth 3 -name authorized_keys -print -exec awk 'NF && $1 !~ /^#/ {print " ->", $1, $NF}' {} \;
Sample output:
/home/crab/.ssh/authorized_keys
-> ssh-ed25519 bang@laptop
-> ssh-ed25519 crabsmith-panel
Check the ownership and permissions on every .ssh directory too — OpenSSH refuses key auth if permissions are too loose, and world-writable .ssh folders are a classic privilege-escalation vector:
sudo ls -ld /home/*/.ssh /home/*/.ssh/authorized_keys 2>/dev/null
Every .ssh directory must be 700 (drwx------) and every authorized_keys file must be 600 (-rw-------), owned by that user.
6. Audit Per-User Cron Jobs, Running Processes, and systemd Units
Before you ever remove or lock a legacy user on a production server, check whether that account is quietly running a database backup cron, a queue worker, or a background daemon:
# List every user's personal crontab
for u in $(cut -d: -f1 /etc/passwd); do
cron=$(sudo crontab -u "$u" -l 2>/dev/null | grep -vE '^\s*(#|$)' || true)
if [ -n "$cron" ]; then
echo "=== crontab for $u ==="
echo "$cron"
fi
done
# Check systemd units configured to run as a specific user
grep -rn "^User=" /etc/systemd/system/ 2>/dev/null || true
# Check live processes by user
ps -eo user:16,pid,pcpu,pmem,cmd --sort=user | head -n 40
Skipping this check is how people accidentally delete an old ubuntu user and wonder three days later why nightly S3 database backups silently stopped running.
7. How to Add, Lock, or Remove a User Cleanly on Ubuntu
Create a clean SSH-key-only deploy user
sudo adduser --disabled-password --gecos "" deployuser
sudo mkdir -p /home/deployuser/.ssh
sudo chmod 700 /home/deployuser/.ssh
# Paste their Ed25519 public key into /home/deployuser/.ssh/authorized_keys (mode 600)
sudo chown -R deployuser:deployuser /home/deployuser/.ssh
Lock an account safely before deleting it
When someone leaves a team, I prefer locking the account first for 7 days (in case any cron job or script still owns files under that UID) before permanently deleting their home directory:
# Lock password, expire account, and disable interactive shell
sudo usermod -L -e 1 -s /usr/sbin/nologin olduser
# Immediately revoke their SSH keys
sudo rm -f /home/olduser/.ssh/authorized_keys
# Kill any lingering SSH sessions or background processes owned by them
sudo pkill -KILL -u olduser 2>/dev/null || true
Permanently remove the user and clean up orphaned files
Once you've confirmed nothing depends on their files (sudo find / -user olduser 2>/dev/null), remove the account cleanly:
sudo deluser --remove-home olduser
If you ever find orphaned files left behind after removing an older account (which show up as raw numeric UIDs like 1002 in ls -la), locate them with sudo find / -nouser -o -nogroup 2>/dev/null and either delete them or chown them cleanly to crab:crab.
8. Five Real-World User & Permission Mistakes to Avoid on Ubuntu
After auditing dozens of production Linux boxes, these are the exact mistakes that keep showing up:
- Sharing one personal SSH key across three teammates. Always give every person their own named Ed25519 key in
authorized_keys(with a clear comment likealice@macbook), so when someone leaves or loses a laptop you delete one line instead of rotating keys for the entire company. - Leaving the default
ubuntucloud-init account unlocked alongside your new deploy user. If you createdcrabas your app/admin user, verify whether/home/ubuntu/.ssh/authorized_keysstill holds old bootstrap keys and remove them cleanly. - Adding your app user to the
dockergroup casually. Membership in thedockergroup is mathematically equivalent to passwordlessrootaccess — anyone indockercan mount/into a container and read/etc/shadowin two seconds. Auditgetent group dockerjust as strictly asgetent group sudo. - Fixing
Permission deniederrors withchmod -R 777. Never do it. Instead, checkid crab,id caddy, andid www-data, and align your PHP-FPM pool user (user = crab) and socket ownership (listen.owner = caddy) so permissions stay tight (755dirs,644files,600.env). - Forgetting to check
/root/.ssh/authorized_keyseven after settingPermitRootLogin no. Clean it out anyway — defense in depth means zero stale keys anywhere on disk.
Making this 2-minute user and SSH-key audit part of your quarterly server checkup (right alongside checking systemctl --failed and testing a database backup restore) keeps even multi-year-old VPSes as clean and trustworthy as the day you provisioned them.
Quick Reference Cheat Sheet
| Audit Question | Command |
|---|---|
| Human login accounts only | awk -F: '$3 >= 1000 && $1 != "nobody" {print $1, $3, $7}' /etc/passwd |
| Every account (local + NSS) | getent passwd | cut -d: -f1 | sort |
| Any non-root UID 0 account | awk -F: '$3 == 0 {print $1}' /etc/passwd |
Members of sudo group |
getent group sudo |
Custom sudoers.d grants |
sudo grep -rnvE '^\s*(#|$)' /etc/sudoers.d/ |
| Active SSH sessions | w |
| Recent logins & IPs | last -n 15 |
| All SSH public keys on box | sudo find /root /home -maxdepth 3 -name authorized_keys -exec cat {} + |
Clean User & SSH Key Hygiene by Default With Crabsmith
When you manage Ubuntu 24.04 or 26.04 servers with Crabsmith, every server follows the exact least-privilege model above out of the box:
- One dedicated non-root Linux user (
crab) owns your sites, deploys, systemd daemons (Daemons), and cron schedules (Schedules). - SSH keys are managed centrally in SSH keys so revoking an old laptop or teammate's key across every server takes one click.
- Crabsmith connects strictly over agentless SSH using its own panel key — zero background root daemon running on your VPS.
Try it on your next Ubuntu server with a 7-day free trial (no credit card required), or read Servers and Getting started.