How to List Users in Linux (4 Methods)
As a Linux administrator, it is an important job to ensure that access to directories and files is granted to select, trustworthy users. This prevents unintended users from accessing the entirety of the Linux file system, thus, safeguarding the integrity of the system. Therefore, it becomes essential to learn about the commands that help you list all users in your Linux system.
There are multiple ways to list users in Linux. Some of them are using commands such as cat, more, less, which are used to read and alter files in Linux. The other method is by using pattern scanning methods with tools such as Awk and Getent. In this guide, let’s look at how to list all users in Linux.
1. List Users Using Cat Command in Linux
Thecat command in Linuxstands for “concatenate” and is used to print, merge, or create files in Linux. The file containing all users’ info on Linux systems is stored in the /etc directory, inside the root folder in a file named “passwd.” Launch the terminal and start typing the following command:
For example, let’s take the user account — “beebom : x : 1001 : 1001 : Beebom,,,,: /home/beebom : /bin/bash.”Here, each field is separated by a colon and denotes the following:
2. Use less and more to List Users in Linux
Similarly, you can use less and more to read the contents of /passwd and display it on the terminal. More and Less are used to view files in the command line. More can be used to view the contents of multiple files and the same is separated by lines, whereas less is used to switch between files.
3. Use Awk Command to List Username in Linux
Awk is a scripting language that’s used for pattern scanning and indexing. One of the primary uses for Awk is to allow users to search, list, and display files that meet a certain criterion set by the user using the command line. This command makes it simple to search for specific files with specific terms on the operating system. Here’s how to list all the users in Linux using the awk command.
4. Use Getent Command to List Linux Users
Getent (short for Get entry) can be used to get the user data from the /passwd file. Getent is exclusively used to get the data (files) from the database. Consider it as “ls” command but for listing file contents instead of directories. The syntax of the same is:
To get the data of a specific user, you can use the following command.
where “abubakar” is the user name. Here’s what you will see as the output.
Getent can also help you count the number of users in your Linux system with this command.
The aforementioned methods were some of the most common and easier ones to list users in Linux. Some of the other ways to list all the users are by usingcutandcompgencommands. Although, the above methods should suffice. If you want to check all the available users in Linux, you could always do so by going to Settings -> Users in any distro.
Beebom Staff
Bringing the latest in technology, gaming, and entertainment is our superhero team of staff writers. They have a keen eye for latest stories, happenings, and even memes for tech enthusiasts.
Add new comment
Name
Email ID
Δ
01
02
03
04
05