Updated: 12 October 2026 · Applies to: Ubuntu 24.04 and 26.04, Debian 13, AlmaLinux 9.8 and 10.2 (tested), macOS 27 (tested), FreeBSD (from the FreeBSD Handbook and manual pages)
To list all users on a Unix-like system, run getent passwd (Linux, FreeBSD and most other Unix systems) or print just the names with cut -d: -f1 /etc/passwd. Most of the names are system accounts for services. To list only the people, filter by user ID (UID): awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd on Linux and FreeBSD. On macOS, use dscl . list /Users UniqueID instead, because local accounts are not kept in /etc/passwd there.
1. List every account (Linux and FreeBSD)
getent passwd # all accounts, including LDAP or other directories cut -d: -f1 /etc/passwd # only the names from the local file wc -l < /etc/passwd # how many local accounts there are
The last lines of getent passwd on our Ubuntu 24.04 test system, after adding two users and one service account:
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash alice:x:1001:1001::/home/alice:/bin/bash bob:x:1002:1002::/home/bob:/bin/bash appsvc:x:999:999::/home/appsvc:/usr/sbin/nologin
Each line is name:password:UID:GID:comment:home:shell. The x means the password hash is stored elsewhere (/etc/shadow on Linux, /etc/master.passwd on FreeBSD, both readable by root only). Use getent rather than reading the file when the server also takes users from LDAP or Active Directory: getent asks every configured source, the file holds local accounts only.
2. List only real users
Linux distributions give people UIDs from 1000 up (the UID_MIN value in /etc/login.defs, 1000 on every system we tested) and keep system accounts below that. UID 65534 is nobody, which is not a person either.
awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd
Output on Debian 13, where the first user created gets UID 1000:
alice bob
Two other ways that give the same list:
getent passwd {1000..60000} | cut -d: -f1 # also finds directory (LDAP) users
lslogins -u # util-linux table view
getent with a range looks up every number, so it takes a few seconds (2 to 15 seconds in our lab containers). lslogins -u prints a table with the last login and whether the password is locked:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 3 0 0 root 1000 ubuntu 0 1 0 Ubuntu 1001 alice 0 1 0 1002 bob 0 1 0
lslogins is in the util-linux package on Ubuntu 24.04, Debian 13 and AlmaLinux. On Ubuntu 26.04 install util-linux-extra first.
3. Accounts that can log in
Service accounts usually have the shell /usr/sbin/nologin or /bin/false, so they cannot log in. This shows every account that has a real shell:
awk -F: '$7 !~ /(nologin|false|sync|shutdown|halt)$/ {print $1": "$7}' /etc/passwd
root: /bin/bash alice: /bin/bash bob: /bin/bash
4. Administrators and group members
getent group sudo # administrators on Ubuntu and Debian getent group wheel # administrators on AlmaLinux, Rocky Linux, RHEL and FreeBSD id alice # UID, main group and all groups of one user groups alice # only the group names
On Ubuntu the result looks like sudo:x:27:ubuntu: the members are listed after the last colon. To add someone, see How To Add User To A Group In Linux?
5. Who is logged in, and the last logins
who # who is logged in now w # the same, plus what each user is running users # only the names last # recent logins and reboots lastlog2 # last login of every account (Debian 13, Ubuntu 26.04) lastlog # last login of every account (Ubuntu 24.04, AlmaLinux)
On Debian 13 and Ubuntu 26.04, last comes from the wtmpdb package and lastlog2 from the lastlog2 package, and the old lastlog command is gone. Install them with apt install wtmpdb lastlog2 if they are missing. The w command is in the procps package; Linux w Command: See Who Is Logged In and What They Do explains its columns.
6. FreeBSD
According to the FreeBSD Handbook and manual pages, getent passwd, the awk filter above and cut work the same way on FreeBSD. FreeBSD also has its own tools:
pw usershow -a # every account, in /etc/master.passwd format (password field shown as *) pw usershow -a -P # the same in a readable layout pw groupshow wheel # members of wheel, who may use su to become root lastlogin # the last login of each user
The Handbook's example user gets UID 1001, and system accounts such as daemon, bind and www run services.
7. macOS
macOS keeps accounts in Open Directory, so /etc/passwd does not list the users you created (its own header says it is read directly only in single-user mode). Tested on macOS 27.0.1 (user name replaced with alice):
dscl . list /Users | grep -v '^_' # accounts, without the _ system accounts dscl . list /Users UniqueID | awk '$2 >= 501' # people only
daemon alice nobody root alice 501
The first user on a Mac gets UID 501. dscl . -read /Groups/admin GroupMembership lists the administrators, and dscacheutil -q user prints every account with its home folder and shell.