How to list users in Linux

A close up photo of a person's hands typing on a laptop keyboard
(Image credit: Shutterstock)

Ever wondered who's on your Linux system? Whether you're a tech pro or just getting started, knowing how to find the list of users is a handy skill. This guide is here to walk you through the simple steps of getting a user list on Linux.

In this how-to guide, we'll cover some basic commands for discovering usernames, user IDs, and more. It's not just about who's who but understanding what's going on behind the scenes in your Linux system.

Whether you're keen on tightening security, fixing problems, or just curious about your Linux setup, this tutorial shares the Linux commands that will produce the information you're looking for.

How to list users in Linux

You'll need to access your Linux command line interface in order to complete the following steps. It would be helpful if you also have a basic understanding of Linux commands, but it's not absolutely necessary.

1. Produce full list of users

(Image: © Future)

The easiest way to obtain a list of users in Linux is to use the getent command.

The getent command retrieves information from Linux's databases, including information about users.

To obtain a full list of users, open your system's command line interface and type the following command: getent passwd

This produces a list of users on the system and also includes (in a very abbreviated format) details about the user ID, group ID, user's home folder, default shell, optional personal information, and whether the user has a password.

2. Produce list of user first names only

(Image: © Future)

To produce a simpler user list, enter the command getent passwd | awk -F: '{ print $1}'

The awk tool is a versatile text processing tool in Linux and is mainly used for pattern scanning and processing.

By specifying print $1, we are instructing Linux to only return the first field of each entry.

The result is a list of first names only without all the additional information we got with the previous command.

However, you'll notice in the example above, that there are many entries like systemd-network and systemd-timestamp which is probably not what you're looking for when you're trying to produce a list of users on the system.

This is because Linux does not distinguish between human users and system accounts created by applications.

We will look at producing a list of just the human users in the next couple of steps.

3. Understanding User Identifiers

(Image: © Future)

Users on the system are given a user identification number known as a UID. We can use this number to separate human and non-human users.

Enter the command grep -E '^UID_MIN|^UID_MAX' /etc/login.defs to return the range of user identification numbers used by human users.

As you can see in the screenshot above, human users on my system have UIDs that are between 1000 and 60,000.

4. Producing a list of human users only

(Image: © Future)

Now, you need to run the command to get a list of human users. Based on the answer I was given in the previous step, my command was getent passwd {1000..60000}.

You'll need to ensure that the numbers in curly brackets in your command reflect the minimum and maximum UIDs you were provided with.

In my example above, I had a list of four people once I had removed all the non-human application and system users.

The getent command is just one of the ways that you can obtain information about users. If you are looking for specific user information, you might want to tailor your command to produce a filtered list that matches your requirements. Filtering or shortening your results is especially helpful if you have a large number of users on your system.

Producing a list of users in Linux can be beneficial for several reasons, including helping administrators identify who has accounts on the system or identifying which users own specific files or processes. Understanding Linux commands means that you can access information whenever you need it in the way that best suits you.


For more help with Linux, check out our guides on how to find CPU information in Linux, how to add users in Linux and how to find a file in Linux.

Emma Street
Contributor

Emma Street is a freelance content writer who contributes technology and finance articles to a range of websites, including Tom's Guide, Top10.com, and BestMoney. She has over 15 years of experience working in technical development within the fintech industry. When not writing about tech, Emma can be found writing romantic fiction, reviewing films, and updating her tea blog.