Knowing who has an account on your server is the first step in keeping it secure. A fresh Linux VPS already has dozens of accounts, but almost all of them are system accounts that cannot log in. This guide shows how to list every user and group, how to pick out the human accounts, and how to see who belongs to which group.
Before you start
- A Linux VPS with Ubuntu 22.04 or 24.04, Debian 12, or AlmaLinux or Rocky Linux 8 or 9.
- An SSH session. Reading the user list needs no special rights; checking login status with
passwd -Sneeds sudo.
Where user accounts live
Local accounts are stored in three plain text files:
/etc/passwd: one line per account with its name, user ID (UID), group ID, home folder and shell./etc/shadow: password hashes and expiry data, readable only by root./etc/group: groups and their extra members.
Each line in /etc/passwd has seven fields separated by colons:
deploy:x:1001:1001:Deploy user:/home/deploy:/bin/bashFrom left to right: username, a placeholder for the password, UID, primary group ID, comment, home folder and login shell.
List all users
The most reliable command is getent, because it also includes accounts from other sources such as LDAP if your server uses them:
getent passwdTo show names only:
getent passwd | cut -d: -f1Bash has a shorter built-in that lists usernames too:
compgen -uCount the accounts with getent passwd | wc -l. Do not be surprised by a number above 20 or 30.
Show only real (human) users
Linux separates accounts by UID range. The ranges are set in /etc/login.defs:
- UID 0 is root.
- UID 1–999 are system accounts, used by services such as
www-data,sshdormysql. On AlmaLinux and Rocky the system range is set bySYS_UID_MAX, normally 999. - UID 1000 and above are normal users created with
adduseroruseradd.65534isnobody, a special account, not a person.
Check the limits on your server:
grep -E '^UID_(MIN|MAX)' /etc/login.defsThen list only regular users with awk:
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1, $3, $6, $7}'Example output:
deploy 1001 /home/deploy /bin/bash
anna 1002 /home/anna /bin/bashAlso list every account that has a real login shell, because a system account with Bash could be a sign of tampering:
getent passwd | grep -vE '(nologin|false|sync|shutdown|halt)$'You should normally see root and your own users only.
Check whether an account can log in
A user with a valid shell may still have a locked password. Check with:
sudo passwd -S deployThe second field shows P for a usable password, L for locked and NP for no password. On AlmaLinux and Rocky the codes are PS, LK and NP, followed by a short note in brackets such as (Password set, SHA512 crypt.).
List groups
List every group on the server:
getent groupEach line shows the group name, a placeholder, the group ID and the extra members:
sudo:x:27:deploy,annaTo see the members of one group, ask for it by name:
getent group sudo
getent group wheelOn Ubuntu and Debian, sudo is the admin group. On AlmaLinux and Rocky it is wheel. Anyone listed there can run commands as root.
Note: A user's primary group does not appear in the member list in /etc/group. For example, deploy is a member of group deploy through its passwd line, not through the group file. Use id to see the full picture.
List the groups of one user
id deployuid=1001(deploy) gid=1001(deploy) groups=1001(deploy),27(sudo)groups deploy prints the same group names in a shorter form.
Check it works
Create a test account and confirm it appears in the human user list, then remove it:
sudo useradd -m testuser
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1}'
sudo userdel -r testusertestuser shows in the list after the first command and is gone after the last.
Troubleshooting
- A user you created is missing from the list: you are probably filtering by UID and the account was made with
--system. Rungetent passwd <name>to see its real UID. passwd -Ssays "Permission denied": it needs root. Run it withsudo.- An unknown account with a UID of 0: only root should have UID 0. A second one is a serious warning sign. Check with
awk -F: '$3 == 0' /etc/passwdand treat the server as possibly compromised. compgen: command not found: you are not in Bash, for example insh. Typebashfirst or usegetent passwdinstead.
Next steps
- Create a new account: Add a new user on Linux.
- Change group membership: Add a user to a group in Linux.
- See who is active right now: See who is logged in (w, who, last).
