How to Display the List of All Users in Linux (Ultimate Guide)

Linux TLDR
Last Updated:
Reading time: 1 minutes

It is important for a Linux administrator to find out all the users on their current system so that they can adjust the rules and privileges for each one.

In this article, you will learn three ways to display the list of all users on your Linux system.

Tutorial Details

DescriptionListing all users in the Linux System
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitescat, compgen, awk
Internet RequiredNo

Method 1: Reading the Passwd File

The traditional and most effective way to display the list of usernames is by reading the “/etc/passwd” file using the cat command.

$ cat /etc/passwd

Output:

Displaying the list of users using the passwd file

Method 2: Using the Compgen Command

Finding the user from the “/etc/passwd” gives you a lot of unnecessary information that can be filtered by just listing the username by using the compgen command.

$ compgen -u

Output:

Displaying the list of usernames using the compgen command

Method 3: Listing the Users Based on Their Home Directory

The above two commands will give you the user’s information that you and your system services created, which may create confusion during differentiation.

If the system administrator has created the user using the “adduser” command, which creates the user home directory, then you can list all the users in your system by reading the “/home/” directory.

📝
If users are using a different home directory or do not have any directory, then this method becomes ineffective.
$ awk -F ":" '{if($6 = /home/) print $1}' /etc/passwd

Output:

Displaying the list of users by reading their home directories

I hope you learn something new today.

We’ll see you again in another article.

Till then, sayonara.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.