How-to

How to List Users on a Linux Server

Every account lives in /etc/passwd, but most of them are system accounts for services. A few commands separate real people, show who is online and who can use sudo.

How do I list every account?

getent passwd | cut -d: -f1
getent passwd | wc -l

getent asks the system's name service, so it includes accounts from LDAP or SSSD if you use them, not just the local file. On a fresh image you will see around 25 to 40 entries, almost all of them system accounts. The format of each line is covered in The /etc/passwd file.

How do I show only real human users?

Human accounts start at a minimum UID set in /etc/login.defs, which is 1000 on current Debian, Ubuntu and RHEL family releases. System accounts use lower numbers, and the nobody account uses 65534.

awk -F: -v min="$(awk '/^UID_MIN/{print $2}' /etc/login.defs)" '$3>=min && $3<65534 {print $1, $3, $6, $7}' /etc/passwd
getent passwd {1000..60000} | cut -d: -f1,6

The first prints name, UID, home folder and shell for each human account. The second uses getent's ability to look up a range of UIDs. On a new machine you should see just the admin user you created; root is UID 0 and is listed separately.

Which accounts can log in at all?

grep -vE '(nologin|false)$' /etc/passwd | cut -d: -f1,7
sudo passwd -Sa 2>/dev/null | awk '$2=="P"'

Accounts with /usr/sbin/nologin or /bin/false as the shell cannot open a shell session. passwd -S shows each account's password status: P has a usable password, L is locked and NP has none. On the RHEL family use sudo passwd -S username per account, since -a is a Debian feature. An account can still log in with an SSH key while its password is locked, so check ~/.ssh/authorized_keys too.

Who has sudo or admin rights?

getent group sudo wheel
sudo grep -rhE '^[^#].*ALL' /etc/sudoers /etc/sudoers.d/

Debian and Ubuntu grant sudo to the sudo group; AlmaLinux, Rocky and CentOS Stream use wheel. The grep finds any extra rules that grant rights to individual users. The sudo command explains how those rules work.

Who is logged in right now?

who -u
w -h
loginctl list-sessions

who lists sessions with the terminal, login time and source address. w also shows idle time and what each user is running. loginctl lists systemd sessions, including those without a terminal. If you see a session you do not recognize, check the source IP and the auth log at once.

Who logged in recently?

last -a -n 20
lastlog -b 0 -t 30
sudo lastb -n 20

last shows recent successful logins, lastlog -t 30 shows each account's last login within 30 days, and lastb lists failed attempts from /var/log/btmp. On distros moving to wtmpdb and lastlog2, use wtmpdb last and lastlog2. A long lastb list from unknown addresses is normal internet noise; Set up fail2ban and key only login cut it down.

Which groups does a user belong to?

id deploy
groups deploy
getent group docker

Membership in docker, sudo, wheel, adm or lxd grants significant power, effectively root for docker and lxd. Review those groups whenever someone leaves the project. Add a user to a group covers adding and removing members.

What should a user audit look like?

  • List human accounts and confirm each one belongs to someone who still needs access.
  • Check members of sudo, wheel and docker.
  • Read every authorized_keys file, including root's.
  • Lock unused accounts with sudo usermod -L -e 1 olduser, or delete them.
  • Look at last and lastb for unexpected sources.

Removing and changing accounts is covered in usermod command and Linux user management.

How do I see what each user is running?

ps -eo user= | sort | uniq -c | sort -rn | head
ps -u deploy -o pid,etime,args --sort=etime

The first line counts processes per account, a quick way to spot an app account that forked far more workers than expected or a user who left a job running for weeks. The second lists one user's processes, newest first. Combined with who, this tells you who is on the box and what they are doing, which is all most small teams ever need from a user audit.

Machines for Small Teams Sharing a Box

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
E1Intel Xeon E3-1240 v34 / 816 GB DDR32x 240 GB SSD2x 1 Gbps$30.52$91.56 (3 months)
S1Intel Xeon E-2276G6 / 1264 GB DDR41x 1 TB NVMe2x 10 Gbps$53.32$53.32 (1 month)
S2Intel Xeon E-2356G6 / 1264 GB DDR41x 1 TB NVMe2x 10 Gbps$58.39$58.39 (1 month)

Keep Reading

The /etc/passwd file

Read the seven fields of /etc/passwd, see how it links to /etc/shadow and /etc/group, and edit accounts safely with vipw and the user tools.

Open

usermod command

Change an existing Linux account with usermod: add groups without losing old ones, rename, move home folders, lock, expire and change shells.

Open

Linux user management

The full life of an account on a server: create, group, change, expire, lock, audit and delete, with the files behind each step.

Open

The sudo command

How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.

Open

FAQ

Quick Answers

Run getent passwd | cut -d: -f1. It includes local and directory accounts.

Real users have UIDs from UID_MIN in /etc/login.defs, usually 1000, up to 65533.

Use who -u or w. loginctl list-sessions shows systemd sessions too.

Check getent group sudo on Debian and Ubuntu, wheel on the RHEL family, and the sudoers files.

A locked password blocks password login, but SSH keys still work unless the account is expired or the key is removed.