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
Description | Listing all users in the Linux System |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | cat, compgen, awk |
Internet Required | No |
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:
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:
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.
$ awk -F ":" '{if($6 = /home/) print $1}' /etc/passwd
Output:
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.