HOW TO VIEW SYSTEM USERS IN LINUX

Published: August 12, 2023 (Updated: Aug 12, 2023)

Enjoying this content? Subscribe to the Channel!

Linux User Management 101: How to List All Users and Groups Instantly (The Essential Commands)


Welcome back to Darren’s Tech Tutorials!

If you’re stepping into the world of Linux system administration—or even just managing your own robust desktop environment—a fundamental skill is knowing exactly who and what is allowed onto your system. Every login, every piece of access, and every permission is tracked using users and groups.

In this quick, essential tutorial, we’re going to demystify the core files of user management and show you the exact commands needed to generate a clean, readable list of every user and every group on your Linux system. These commands are fast, reliable, and work across nearly all Linux distributions, whether you are running CentOS, Ubuntu, Debian, or anything else!

Let’s dive into the terminal!


The Foundation: The /etc/passwd File

The core database for every user account—both human and system-level—is the /etc/passwd file. This file contains crucial information like the user’s home directory, default shell, and most importantly, the username itself.

To view the entire raw content of this database, we use the cat command:

cat /etc/passwd

What you will see: A long list of entries, separated by colons (:). The format is typically: username:password_placeholder:UID:GID:comment:home_directory:shell.

Filtering for Clarity: Listing Only Usernames

While seeing the full /etc/passwd file is informative, sometimes you just need a clean list of usernames. To achieve this, we harness the power of the cut command.

The cut command allows us to specify a delimiter (the separator character) and then select only the specific field we want. Since the username is always the very first field in the /etc/passwd file, we select field 1.

Here is the essential command to list only the usernames:

cut -d : -f 1 /etc/passwd

Breaking down the command:

  • -d :: Specifies that the delimiter (separator) is a colon.
  • -f 1: Instructs the command to output only the first field.
  • /etc/passwd: The input file to process.

This command instantly delivers a clean, vertically listed output of every username on your system—perfect for auditing or scripting!


Diving into Group Management (/etc/group)

Just as important as users are groups. Groups define what resources users have access to, and they are essential for managing permissions efficiently. The central database for all groups on your system is the /etc/group file.

To see all group information, including which users belong to which groups, use the cat command:

cat /etc/group

What you will see: Similar to the passwd file, the output is colon-separated data, showing the group name, the group password placeholder, the GID (Group ID), and finally, a list of users belonging to that group.

Listing Just the Group Names

Like with users, we often only need the name of the group, not all the surrounding data. Fortunately, the structure of the /etc/group file is identical to the /etc/passwd file regarding the placement of the name (it’s the first field).

We can reuse the exact same logic with the cut command, just pointing it at the new file:

cut -d : -f 1 /etc/group

This simple command provides a definitive list of every configured group on your system.


Summary and Next Steps

Mastering these four simple terminal commands immediately elevates your system administration capabilities:

Goal Command
View All User Data cat /etc/passwd
List Only Usernames cut -d : -f 1 /etc/passwd
View All Group Data cat /etc/group
List Only Group Names cut -d : -f 1 /etc/group

These commands are crucial for security audits, scripting, and general monitoring. Knowing exactly who and what is logging into your server is the first step toward maintaining a secure and stable environment.

Give these commands a try right now on your favorite Linux distribution!

If you found this quick guide useful, don’t forget to Like this post, Subscribe to Darren’s Tech Tutorials for more practical Linux tips, and leave a comment below letting us know what essential command you want us to cover next! Happy administering!