How to List Users and Groups on Ubuntu Linux

  • Home
  • Blog
  • How to List Users and Groups on Ubuntu Linux
RDPextra
DateFeb 13, 2025

On Ubuntu you can list users and groups with a few built-in commands. User accounts are stored in the /etc/passwd file, which holds details such as the username, user ID (UID) and home directory. Groups are stored in /etc/group, which holds the group name, group ID (GID) and its members. See the passwd manual page for the full file format.

Ubuntu has system users and regular users. System users usually have a UID below 1000 and run background services, while regular users have a UID of 1000 or higher and represent real people. This guide shows the commands to list both, count them and see who is logged in.

Why List Users and Groups on Ubuntu?

  • Security. Spot accounts that should not exist.
  • Access control. Check who belongs to which group and what they can reach.
  • Troubleshooting. Find misconfigured accounts when a permission problem appears.
  • Maintenance. Clean up inactive or unneeded accounts. If you need to add one, see our guide to creating a new user on Ubuntu.

List All Users on Ubuntu

List users with /etc/passwd

Print the whole file to see every account:

cat /etc/passwd

Each line has seven fields separated by colons:

username:x:UID:GID:comment:home_directory:shell
FieldMeaning
usernameThe account name
xPassword placeholder. The real hash is stored in /etc/shadow
UIDThe numeric user ID
GIDThe primary group ID
commentOften the full name or a description
home_directoryThe user’s home folder
shellThe default login shell

List only usernames with cut

To show just the first field, use cut:

cut -d: -f1 /etc/passwd

List users with getent

The getent command reads from the system databases, so it also shows users from network sources such as LDAP, not only the local file.

getent passwd

List only regular users

Regular users have a UID of 1000 or higher. The special user nobody has UID 65534, so the command below leaves it out:

getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1}'

Count the Users on Ubuntu

To count all accounts in the local file:

wc -l /etc/passwd

To count only regular users:

getent passwd | awk -F: '$3 >= 1000 && $3 < 65534' | wc -l

List Groups and Group Members on Ubuntu

List all groups

getent group

List the members of one group

For example, to see who is in the sudo group:

getent group sudo

List the groups a user belongs to

groups username
id username

Replace username with the account name. The id command also shows the UID and GID. If a user needs admin rights, our sudo guide explains how sudo works.

List Logged-In Users on Ubuntu

These commands show who is using the system right now:

who

Shows logged-in users with their terminal and login time.

who

w

Shows more detail, such as how long each session has been idle and what each user is running. Use w -i to show the IP addresses of connected users.

w

users

Prints a simple, space-separated list of logged-in usernames.

users

last

Shows the login history, which is useful for checking user activity over time.

last

Frequently Asked Questions

How do I list all users on Ubuntu?

Run cat /etc/passwd or getent passwd. To show only the names, use cut -d: -f1 /etc/passwd.

How do I check which users are logged in?

Use who, w or users. They show active sessions and login times.

How can I tell system users from regular users?

System users usually have a UID below 1000, and regular users have a UID of 1000 or higher. Filter the UID field to separate them, as shown in the awk command above.

Conclusion

Use /etc/passwd or getent passwd to list users, getent group to list groups, and who, w or last to see who is logged in. Check these lists from time to time to keep your Ubuntu system secure and well managed.

Related Reading

Author avatar
Evan Allenn

Evan Allenn writes technical guides and troubleshooting articles at RDPextra. He has 3 years of experience in the hosting industry and focuses on clear, step-by-step instructions for RDP, VPS and server users.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x