How to List users in Linux? [Linux List Users]

Unlock the secrets of Linux user and group management with our comprehensive guide. Learn diverse commands, from /etc/passwd and /etc/group exploration to advanced techniques using getent, who, id, and groups. Master the command line and enhance your Linux administration skills today!

Updated: 18 Dec, 24 by Susith Nonis 7 Min

List of content you will read in this article:

Embark on a journey through the heart of Linux administration as we unravel the intricacies of user and group management in this comprehensive guide. Navigating the Linux environment requires more than a graphical interface—understanding how to list users and groups on Linux efficiently is a fundamental skill for any administrator or enthusiast.

This article delves into various methods and commands for listing users and groups, from examining classic files like /etc/passwd and /etc/group to leverage powerful commands such as getent, who, id, and groups. Whether you’re a seasoned administrator seeking advanced techniques or a beginner eager to master the basics, this guide equips you to handle Linux user and group management with confidence.

Before diving into how to list users and groups on Linux, you may want to check out our article on How to Create a User in Linux.

Linux offers several ways to list users on your system, leveraging its robust command-line interface. Whether you're managing a server or exploring Linux for the first time, learning to list local users in Linux is crucial for effective system management.

List Usernames Using the /etc/passwd File

The /etc/passwd file is a reliable source of user information on Linux. Use this command to retrieve a list of usernames:

cat /etc/passwd | cut -d: -f1

This command reads the /etc/passwd file and extracts the username field, delivering a clean, straightforward list of users on your system.

List Usernames Using the cut Command

The cut command is a powerful text-processing tool that can efficiently extract usernames:

cut -d: -f1 /etc/passwd

Here, -d: defines the delimiter as a colon, and -f1 extracts the first field (username). It’s a quick way to list all usernames in Linux.

List Usernames Using the cut Command

List Usernames Using awk

awk is another versatile text-processing utility. The following command lists users using awk:

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

This command defines the colon as the field separator (-F:) and instructs awk to print the first field (username). It provides an elegant alternative to the cut command.

List Usernames Using awk

The getent command is a flexible way to query Linux system databases, including user data. Here’s how you can list users:

getent passwd | cut -d: -f1

This command combines getent with cut to extract usernames from system databases. It’s especially useful in environments with centralized authentication systems.

List Users on Linux Using getent

To check who is logged into your Linux system, use the who command:

who

This simple yet effective command displays logged-in users, their terminal sessions, and login times, giving you a quick overview of active connections.

Alternatively, use the w command for more detailed information:

w

The w command provides a summary of logged-in users, along with details like the processes they are running, system uptime, and load averages.

Before continuing this post, we recommend checking out the article on How to Add Users in a Group in Linux.

Groups are essential for managing permissions in Linux. The /etc/group file contains group data, which you can access using the following command:

cat /etc/group | cut -d: -f1

This command extracts the group names from the /etc/group file, offering a clear list of all groups on the system.

List Groups Using getent

You can also use getent to list groups:

getent group | cut -d: -f1

This approach retrieves group names directly from the system’s database, providing an efficient alternative to manually parsing the /etc/group file.

List Groups Using getent

Check Groups for a User

To see the groups a specific user belongs to, use the groups command:

groups [username]

Replace [username] with the target user’s name to display their group memberships. This is particularly helpful for checking permissions.

Use the id Command for Detailed Information

The id command provides a detailed breakdown of user and group IDs:

id

It’s a powerful tool for gaining deeper insights into user and group relationships. To check details for a specific user, use:

id [username]

Once you’ve mastered listing users and groups, consider the following tips to enhance your Linux administration skills:

  1. Filter Results: Combine commands with grep to narrow down specific users or groups. For example:

     cat /etc/passwd | grep 'admin'
  2. Export Data: Save user or group lists to a file for further analysis:

    getent passwd > user_list.txt

  3. Automate Tasks: Use shell scripts to automate user and group management, saving time and reducing errors.

Inactive user accounts can pose a security risk, especially on multi-user systems. To identify accounts that haven't been used recently, you can check the /var/log/wtmp file or use the lastlog command:

lastlog

This command displays the last login times for all users. By reviewing this information, you can identify accounts that may require deactivation or further investigation. Automating this process with scripts can also help maintain a secure and organized Linux system.

For administrators managing large systems, analyzing user and group data programmatically can save significant time. By writing shell scripts, you can automate tasks such as extracting specific users, identifying inactive accounts, or auditing group memberships. For example, a script can loop through the /etc/passwd file to identify users who haven't logged in recently or verify consistent group assignments. This approach not only streamlines Linux user and group management but also ensures accuracy and compliance in complex environments.

Conclusion

In the vast and dynamic landscape of Linux, mastering user and group management is essential for effective system administration. From the fundamental exploration of `/etc/passwd` and `/etc/group` files to the versatility of commands like `getent` and `who`, you've gained insights into different approaches for the retrieving user and group information. Whether you prefer the simplicity of `cut` or the detailed breakdown offered by commands like `id` and `groups`, each method adds a valuable tool to your Linux toolkit.

As you navigate the intricate web of user and group relationships, remember that the command line is your ally. The ability to Linux list users and groups efficiently is not merely a technical skill; it's a gateway to understanding the inner workings of your Linux environment.

Continue to experiment with these commands, incorporating them into your daily workflow, and at the end, visit the post on How to Switch User in Linux [Linux Change User]. Tailor them to your preferences and requirements, and soon you'll find yourself navigating the Linux landscape with confidence.

Happy Linux-ing!

People also read: 

To list users in Linux command line, you can employ various methods, such as utilizing the '/etc/passwd' file or commands like 'getent.' These techniques offer a comprehensive view of all users on your system, allowing you to manage and navigate user configurations efficiently.

Linux list users' typically refers to obtaining a concise list of user names, whereas 'Linux list all users on the system' provides a more detailed overview, including user IDs, group memberships, and other relevant information. Both approaches use commands like 'cut' or 'getent' for effective user listing.

Yes, you can refine your user listing in Linux by identifying admin users. Utilize commands like 'getent' or 'cut' along with additional filters to narrow down the results and list only users with administrative privileges, providing a focused view of users with elevated access.

Regularly updating the Linux list of users is advisable, especially in dynamic environments. Commands like 'who' or 'getent' can help you monitor real-time user activity, ensuring that your user information remains accurate and aiding in the timely identification of potential security issues.

Yes, commands like 'cut,' 'getent,' and 'who' for listing users in the Linux command line are standard across most distributions. However, slight variations might exist in file paths or default configurations. Always refer to your distribution's documentation for precise details when executing user-listing commands.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.

user monovm

Lowell Friesen

2025, Mar, 25

This guide is such a gem for anyone diving into Linux administration. The step-by-step approach to managing users and groups is both comprehensive and easy to follow, making it perfect for those new to Linux as well as seasoned pros looking to refresh their skills. Highlighting different methods like using `/etc/passwd` and commands like `getent` and `id` gives a great variety of options. With these insights, anyone can handle Linux user management with more confidence and efficiency. Great work!