TechEarl

How to List Users and Groups on Linux

List every user and group from /etc/passwd and /etc/group with getent, tell human accounts from system ones by UID, and see which groups a user belongs to.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
List all Linux users and groups from /etc/passwd and /etc/group with getent, and tell human accounts from system accounts by UID.

The user and group databases are plain files, so listing them needs no special tool, no root. Read them with getent, which also covers users defined in LDAP or other directory backends, not just /etc/passwd:

bash
getent passwd      # every user
getent group       # every group
Terminal showing getent passwd and getent group output: the user and group databases with their names, UIDs, GIDs, home directories and shells.
getent reads the full user and group databases, including any directory backends, not just the local files.

Just the usernames

The first colon-separated field of each line is the name:

bash
getent passwd | cut -d: -f1        # all usernames
getent group | cut -d: -f1         # all group names

cut -d: -f1 splits on the colon and keeps field one. (For more on slicing columns, see grep and print a specific column.)

Human accounts vs system accounts

Most entries in /etc/passwd are system accounts (daemon, www-data, sshd), not people. They are separated by UID. On most distros, regular human accounts start at UID 1000:

bash
# Real login users (UID >= 1000, excluding nobody at 65534)
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1}'

The third field ($3) is the UID. That one-liner is the honest answer to "who can actually log in here". (awk -F: sets the field separator to a colon.)

Which groups is one user in?

bash
groups deploy        # group names for one user
id deploy            # names plus UIDs and GIDs

And the reverse, who is in a group:

bash
getent group developers        # the member list is the last colon field

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxgetentUsersGroupsSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts