List All Users
getent passwd
getent reads every user source the system is configured for: the local file and, if configured, a directory service such as LDAP. On a typical server it prints the same lines as the local file:
cat /etc/passwd
Neither command needs sudo. These commands work the same on Ubuntu, Debian, AlmaLinux, and Rocky Linux.
Names Only
cut -d: -f1 /etc/passwd
getent passwd | cut -d: -f1
-d: splits each line at the colons and -f1 keeps the first field. In bash, compgen -u prints the same list of names.
What Each Field Means
A line looks like this:
deploy:x:1000:1000:Deploy User:/home/deploy:/bin/bash
| Field | Example |
|---|---|
| 1. Name | deploy |
| 2. Password | x (stored elsewhere) |
| 3. User ID | 1000 |
| 4. Group ID | 1000 |
| 5. Comment | Full name |
| 6. Home | /home/deploy |
| 7. Shell | /bin/bash |
The x means the password hash is kept in /etc/shadow, which only root can read.
System Accounts and Human Users
Most entries belong to services, such as www-data, sshd, or systemd-network. On current distributions, accounts for people start at user ID 1000; the range is set by UID_MIN and UID_MAX in /etc/login.defs. The account nobody has a very high ID, usually 65534, and is not a person. To list human users only:
awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd
To list accounts that can log in with a shell, filter out the nologin and false shells:
grep -vE 'nologin|false' /etc/passwd | cut -d: -f1
Remember that root has user ID 0 and a real shell, so it appears in the second list but not in the first. A service account with a real shell is worth a closer look: it may have been created by hand for a task that no longer exists.
Who Is Logged In Now
| Command | Shows |
|---|---|
who | Sessions, terminal, login time, source |
w | Sessions plus load and current command |
users | Names only |
whoami | Your own account |
last lists recent logins and reboots on systems that keep the classic login records. Debian 13 no longer ships it; there wtmpdb last from the wtmpdb package does the same job. For failed SSH logins, read the SSH service log with journalctl.
Check One User
id deploy
getent passwd deploy
id shows the user ID and all groups; if the user does not exist, it says so. In a script, the exit status of getent passwd deploy tells you whether the account exists.
List Members of a Group
getent group sudo
getent group wheel
The last field lists the supplementary members. Users whose primary group it is are not listed there; id shows those. Use this to review who has admin rights, and see how to add a user to a group to change membership.
Use the List in a Script
To act on every human user, combine the awk filter with a loop, as explained in the bash for loop guide:
for u in $(awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd); do
echo "$u: $(getent passwd "$u" | cut -d: -f6)"
done
To create new accounts, see useradd vs adduser.