How to List Users in Linux: Commands and Tips

How to List Users in Linux: A Comprehensive Guide

Knowing how to list users in Linux is extremely important when managing client PCs and servers, as access control, audit trails, user tracking, data integrity, compliance, and incident response are critical priorities.

In this guide, we will review the best techniques for Linux to list users effortlessly. After reading this Linux List Users guide, you’ll be proficient enough to list all users in Linux for security and compliance reasons. Let’s get started! 

Introduction to User Management in Linux

User management in Linux servers comes down to two core tasks: creating Linux user accounts and keeping an eye on them for security. When you need to create a user, you’ll use essential Linux commands like useradd and passwd. For example:

sudo useradd -m username  
sudo passwd username 

But your job doesn’t end there—you also need to monitor existing users. Commands like cat /etc/passwd, getent passwd, and last help you track who has access and when they log in. Compared to Linux vs Windows servers, Linux gives you finer control through the terminal, which is why it’s a top choice for Linux VPS hosting. By mastering both account creation and monitoring, you keep your system secure and well-organized.

Here are the common reasons why you must learn the proven methods to list users in Linux:

  • Access Control
  • Audit And Tracking
  • Accountability
  • Data Integrity
  • Compliance With Regulations
  • Role-Based Access
  • Security Monitoring
  • Incident Response
  • Access Recovery
  • Prevent Resource Misuse

How to List Users in Linux: Basic Commands

Listing all users in a Linux server is pretty simple when you use the following Terminal codes:

The Linux Command who

  1. Press Ctrl + Alt + T to bring up the Terminal.
  2. Type who and press Enter.
  3. You’ll get results on the Terminal app that resemble the following screenshot.
  4. The above image shows all the users currently set up in the Linux server or client PC.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

The Linux Command who

This Linux command shows information about users currently logged into the system. It typically displays:

  • Username
  • Terminal (TTY)
  • Login date and time
  • Remote host (if applicable)

Linux Command users

  1. Bring up the Linux Terminal window by pressing Ctrl + Alt + T all together.
  2. Type in users and hit the Enter key.
  3. You’ll see all the currently logged-in users in a single line of text.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Linux command users

  1. For example, if there are currently 5 users logged into a Linux Virtual Dedicated Server (VDS), you’ll see the following text line in the Terminal app:
user1 user2 user3 user4 user5

In an Ubuntu Linux Terminal or for the matter any other Linux distros, the users command shows the usernames of currently logged-in users, printed in a single line, space-separated.

If it shows john alice john, it means, john is logged in twice and alice is logged in once.

Using the /etc/passwd File to List All Users in Linux

The /etc directory in the Linux kernel contains all the system-wide configuration files and shell scripts. One of the important files in this directory is the passwd file. You can access it either by using the Terminal app to display its contents, which are, in turn, the user account details, or by accessing the file and opening it manually using a text editor.

If you wish to use the Terminal app, open it, enter the following command, and hit the Enter key:

cat /etc/passwd

You’ll get the user database as displayed in the screenshot below:

Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

cat /etc/passwd

Alternatively, follow these steps to access the user account database using the Linux Files app:

  1. Double-click on the Home icon in the bottom right corner of the Ubuntu home screen. Use any file manager or Nautilus in other Linux distros.
  2. Press Ctrl + L to focus and select the file system address bar at the top of the Files app.
  3. Type /etc and hit Enter.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Etc folder

  1. Scroll down to the bottom and select the passwd file just above the rmt file. The rmt file shows a cogwheel icon, so you can’t miss it.
  2. Right-click on the passwd file and select the Open With Text Editor option.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Open With Text Editor

  1. You can now see the contents of the passwd database.
  2. One line item corresponds to one user account. 
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Linux user details

Viewing Users With getent

The getent command in Linux allows you to fetch entries from administrative databases. These databases are often supported by the Name Service Switch (NSS). Here are the databases that are linked to user accounts:

  • passwd – user accounts
  • group – group accounts
  1. Open the Terminal in the Linux system from the Show Apps menu.
  2. Type in getent passwd and press the Enter key.
  3. All of the users in the Linux system will be shown as given in the screenshot below:
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Viewing Users With getent

  1. Here’s how to interpret the records or line items:

If you get this: john:x:1001:1001:John Doe,,,:/home/john:/bin/bash

Interpret these colon-separated data as the items outlined below:

  • john – username
  • x – password placeholder (actual password is in /etc/shadow)
  • 1001 – user ID (UID)
  • 1001 – group ID (GID)
  • John Doe,,, – user information (comment field, often used for full name)
  • /home/john – home directory
  • /bin/bash – default shell

List Users in Linux Using Graphical User Interface

  1. Click on the Show Apps icon in the bottom left corner of your Linux home screen.
  2. Open the System Monitor app from the Show Apps drawer.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

System monitor

  1. Click on the Main Menu icon (the hamburger menu icon) and select All Processes.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

All processes

  1. Now go back to the Processes tab again in the System Monitor app and look below the User column to find all the users of the Linux system you’re administering.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

All users

Checking Active Users in Linux

You can easily get tabulated data for active users in your Linux server or client PC by executing the last command in the Terminal app by following these steps:

  1. Open the Terminal app by pressing the Ctrl + Alt + T keys.
  2. Type in last and hit Enter.
  3. The Terminal app will display a complete list of all active users, as shown in the screenshot below.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Last command

  1. Each line item in the Terminal app result corresponds to the following from left to right:
    • <username>
    • <tty>
    • <ip/hostname>
    • <login time>
    • <logout time>
    • <duration>

Tips for Managing User Accounts in Linux

Follow these expert tips to effortlessly manage user accounts in Linux:

  • Regularly review user accounts to ensure only active and necessary accounts are present.
  • Use strong and unique passwords for each user to enhance security.
  • Limit root access by using sudo and granting minimal privileges to users.
  • Avoid using default usernames like admin or root for better security.
  • Set account expiration dates for temporary users to prevent forgotten accounts.
  • Monitor login attempts to detect suspicious activity early.
  • Enforce password policies to require complex passwords and regular changes.
  • Implement group management to easily control access to resources for multiple users.
  • Audit user actions using logs to ensure compliance and track any issues.
  • Create backup accounts with limited privileges in case of an emergency.

FAQs About Listing Users in Linux

How do I list all users in Linux?

Who’s hanging out on your Linux system? Let’s peek at the guest list! My go-to command is:

cut -d: -f1 /etc/passwd  

This command lists only the usernames by processing the system’s user database file. The command works by splitting each line at colons (-d:) and printing just the first field (-f1). 

While /etc/passwd contains additional account details like UIDs and shells, this approach indeed gives you a clean username list. Both human and system users will appear. So, it becomes easier for you to separate real users from regular allowed bots. 

For interactive use, you might pipe this to less for easier reading: cut -d: -f1 /etc/passwd | less.

What commands can I use to show users in Linux?

Here are common commands to list Linux users:

  • cat /etc/passwd  
  • cut -d: -f1 /etc/passwd  
  • getent passwd  
  • awk -F: ‘{print $1}’ /etc/passwd  
  • compgen -u  
  • lslogins -u  
  • users  
  • who  
  • w  
  • last  
  • id -un  
  • echo $(ls /home)  
  • grep -E “/home/.*” /etc/passwd | cut -d: -f1 

Systemd systems add:

  • loginctl list-users

For LDAP/AD:

  • getent passwd | grep ‘domain\\’

How does the /etc/passwd file store user information?

Here’s how the /etc/passwd Linux file stores user information:

  • Format: Each user gets one line with 7 colon-separated fields
  • Field 1: Username (e.g., alice)
  • Field 2: Password placeholder (x means hashes are in /etc/shadow)
  • Field 3: UID (User ID number)
  • Field 4: GID (Primary Group ID)
  • Field 5: GECOS (Full name/description)
  • Field 6: Home directory path (e.g., /home/alice)
  • Field 7: Login shell (e.g., /bin/bash)

Example line:

alice:x:1001:1001:Alice Doe,,,:/home/alice:/bin/bash

What is the difference between active and all users in Linux?

Find below a simple explanation for active vs all users in Linux:

Active Users

These users are logged in now and using the system as we speak (e.g., via SSH, GUI, or terminal). Commands like who or w show these users.

All Users

All users are all of the accounts, logged in or not, that exist on your Linux PC or server. This includes system accounts (like root) and inactive human users. View them with cat /etc/passwd.

Key Difference

Active: Using the PC now.

All: Every account ever created, even unused ones.

How can I check logged-in users in Linux?

Find below the quick and easy way to check logged-in users in Linux using a graphical user interface (GUI)-based method and a command line interface (CLI)-based method:

GUI Method to Check Logged-In Users

  1. Open Settings (or System Monitor on some distros like Ubuntu).
  2. Navigate to the Users or Session tab.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

active users on ubuntu linux

  1. Active users appear with their names and login status.

Alternative: Using a Command

  1. Open the Terminal app in your Linux distro, like Ubuntu.
  2. Type who and press Enter.
  3. You’ll see all the active users in the Terminal window.
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

Who command

What tools can I use to manage user accounts in Linux?

Here are the Linux tools you can use to manage user accounts:

  1. useradd – A command-line tool to create new user accounts with specified properties like home directory and shell.
  2. usermod – It’s used to modify existing user accounts, such as changing the username, group, or shell.
  3. passwd – It sets or changes the password of a user account, enforcing password policies.
  4. deluser/userdel – It removes a user account and optionally deletes its associated home directory and files.

Can I list users in Linux using Bash?

Yes. You can list users in Linux using Bash with the following command:

cut -d: -f1 /etc/passwd
Learn how to list all users in Linux using commands like cat, cut, and getent. Discover tips for managing and viewing user accounts.

List users in Linux using Bash

About The Author
A man with short, light brown hair and a trimmed beard, wearing a beige sweater, looks directly at the camera against a dark background.
Liutauras is the Head of Customer Support Team with five years of experience in the fast-paced cloud hosting industry. With a strong passion for software engineering and cloud computing, he continuously strives to expand his technical expertise while prioritizing client satisfaction. Liutauras is committed to proactive support and providing valuable insights to help clients maximize their cloud environments.
Subscribe to our newsletter