In the world of Linux administration, keeping a safe and well-organized system depends on effective user account management. In addition to offering insightful information about the user base, the ability to list users is a critical step in many administrative activities. Learning the art of identifying users in Linux is essential, whether you’re troubleshooting, keeping an eye on system activity, or just making sure user rights are set correctly. We’ll look at the many commands and methods that enable administrators to explore and understand the user base in a Linux environment in this article. For security within the operating system and managing user access, you should add a user to a group in Linux.

One essential task of Linux system administration is user management. Understanding who has access to the system is essential for large businesses to properly add, remove, and allocate new user privileges. You will learn how to list users on a Linux-based system by following this article. The manual outlines four listing techniques and clarifies key ideas in user administration.

Requirements

  • A Linux-powered system.
  • The ability to operate a terminal or command line.

Listing Linux Users

A single user’s username, home directory, login shell, and user ID (UID) are all contained on a single line in the file. Multiple methods to access the data in /etc/passwd and list users on Linux distributions are presented in the following sections.

The tutorial uses the following commands:

  • cat Command
  • awk Command
  • getent Command
  • less Command

User List for the command “cat”

A straightforward way to list the contents of the etc passwd file is to use the cat command.

Type this to see the file:

cat /etc/passwd

The system outputs the entire file, containing all of the system users.

system outputs entire file with all the users on the system

Use the wc command to count the number of lines and pipe the output of the previous command to observe the number of users only:

cat /etc/passwd | wc -l

The entire number of users is reflected in the number of lines in /etc/passwd.

displays total number of users

Enumerate Users Increasingly Using Terminal Pagers

It’s helpful to restrict how much of the /etc/passwd file output is shown at once on systems with lots of users. To read over the contents of the file line by line or page by page, use a terminal pager command, such as less or more.

Enter to open etc passwd using less.

less /etc/passwd

The output displays the file’s first page. When the list reaches the end of the terminal screen, it ends. To navigate through the file, use the keyboard.

first page of file appears in output

To achieve a similar outcome, use more. The functionality of this command is more restricted and it is older:

more /etc/passwd

using more to get similar result

Use the awk Command to List Users

To list the usernames only—without any further details about individual users—use the awk program. The colon (:) that separates the data fields in /etc/passwd instructs awk to output only the first field on each line.

awk -F':' '{ print $1}' /etc/passwd

list users with awk command

To view the results on individual pages, use the combination of less and awk.

awk -F':' '{ print $1}' /etc/passwd | less

User’s List using getent Command

The getent command searches the system database and displays entries. The etc nsswitch.conf file contains a list of the searchable databases. By default, the file contains the passwd database.

Enter the following to see the complete contents of the passwd database:

getent passwd

The output is identical to what the cat command produced.

list users with getent command

Getent, however, can be used to look for specific people. With the help of following syntax for further procedure:

getent passwd [username]

The command displays the relevant passwd entry line if the user is present on the system.

command shows related passwd entry line

Listing Linux System and Normal Users

System users and regular users are the two categories of users on Linux-based systems.

  • System users are entities that the system has formed to execute non-interactive processes—that is, background operations that don’t need human interaction. With administrative access, root is the most significant system user.
  • Human users created by root or another user with root access are known as normal users. Every regular user has a home directory where they save their files and a login shell.

Linux users, both system and regular, are uniquely identified by their user IDs (UIDs). System user UIDs range from 0 (root user) to 999. Normally, UIDs for normal users start at 1000, and the next smallest unused UID is assigned to each newly created user.

To get the UID range for common users, use the grep command to search through the information in the etc login defs.

grep -E '^UID_MIN|^UID_MAX' /etc/login.defs

This example’s output demonstrates that a typical user can receive UIDs as tiny as 1000 and as large as 60000.

output shows information stored

To search the passwd database by UID, use getent:

getent passwd [UID]

The user entry linked to the UID is displayed in the output.

output shows user entry related to UID

To find users inside a range, combine UIDs with getent:

getent passwd {[first-UID]..[last-UID]}

All of the users inside the given UID range are now listed by the command.

command lists all users within specified uid range

Final Words on Listing Users in Linux

Managing user accounts effectively is a core component of Linux system administration. ‘ls, cat, or getent’ commands can be used to quickly and efficiently enumerate users, revealing crucial information and streamlining administrative tasks. Keeping a safe, well-organized, and functional Linux environment becomes easier with the ability to list users as you navigate the many landscapes of user permissions, groups, and system operations.

By adding these methods to your repertoire of skills, you enable yourself to monitor and resolve user-related problems more effectively, which enhances the overall stability and dependability of your Linux system. You learned how to identify the total number of users in any Linux distribution, search for users, and list all Linux users in this article.