Skip to content
Log In Sign Up info@muvcloud.com

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
FieldExample
1. Namedeploy
2. Passwordx (stored elsewhere)
3. User ID1000
4. Group ID1000
5. CommentFull 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

CommandShows
whoSessions, terminal, login time, source
wSessions plus load and current command
usersNames only
whoamiYour 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.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations