Blogs

VMware Explore 2025: 10 Revolutionary Product Launches and Innovations
August 28, 2025
CrowdStrike to Acquire Onum, Report Strong Q2 Results
September 1, 2025How to List Users in Linux?
In Linux, managing user accounts is a fundamental task for system administrators and power users. Whether you are setting up user permissions, monitoring system access or performing routine maintenance, knowing how to list users in Linux is essential. Fortunately, Linux offers several ways to display both system and regular users, using built-in commands and files. This article will guide you through the various methods to list users, get usernames and understand the structure behind user management in Linux systems like Ubuntu.
Understanding List Users in Linux
Before diving into the commands, it is helpful to understand how Linux categorizes users. Broadly speaking, there are:
- System Users: These are users created by the system or during package installations. They typically run background services and processes.
- Regular Users: These are user accounts created for human users to log in and interact with the system.
Both system and regular users are stored in the /etc/passwd file, along with important metadata like user ID (UID), group ID (GID), home directory and login shell.
How to List Users in Linux?
There are multiple ways to List Users in Linux all users in a Linux system. Here are the most common and reliable methods.
1. Viewing the /etc/passwd File
The primary method to list all users on a Linux system is by inspecting the /etc/passwd file.
cat /etc/passwd
Each line in this file represents a user, formatted as:
username:x:UID:GID:comment:home_directory:shell
Example output:
john:x:1001:1001:John Doe:/home/john:/bin/bash
To extract just the usernames from the /etc/passwd file:
cut -d: -f1 /etc/passwd
This will return a list of all usernames on the system including both regular and system users.
2. Using the getent Command
Another method to list users in Linux is with the getent command, which retrieves entries from administrative databases supported by the Name Service Switch (NSS). This is a more flexible approach especially in environments using Lightweight Directory Access Protocol or other authentication mechanisms.
getent passwd
Like cat /etc/passwd, this lists all users but through the NSS interface.To show only usernames:
getent passwd | cut -d: -f1
Read more: How to Fix Kali Linux Black Screen?
Filtering Regular Users
In Linux, user IDs (UIDs) help distinguish between system and regular users:
- System users typically have UIDs below 1000.
- Regular users generally have UIDs of 1000 or higher.
To list only regular users, use:
awk -F: ‘$3 >= 1000 && $3 < 65534 { print $1 }’ /etc/passwd
This command filters the /etc/passwd file and shows only users with UIDs in the typical range for human users.
Alternatively, using getent:
getent passwd | awk -F: ‘$3 >= 1000 && $3 < 65534 { print $1 }’
Read more: 40 Linux Commands Every Linux User Must Master
How to List Currently Logged-In Users?
If you are looking to find out who is currently logged into the system, rather than a list of all accounts, use one of the following commands:
1. who Command
who
This will show usernames, login terminals and login times.
2. w Command
w
The w command gives a more detailed output including the current activity of each user.
3. users Command
users
This outputs a simple list of logged-in usernames.
How to List Usernames in Linux?
To list only usernames (without extra information like UID or home directory), use:
cut -d: -f1 /etc/passwd
This is particularly useful for scripting or automation tasks where you need a clean list of usernames.
For example, to save the list to a file:
cut -d: -f1 /etc/passwd > all_users.txt
To count the total number of users:
cut -d: -f1 /etc/passwd | wc -l
How to Get User Details in Linux?
To get detailed information about a specific user, you can use the id command:
id username
Example:
id john
This might return something like:
uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)
You can also check the user’s home directory and shell by using:
getent passwd john
Which returns a line like:
john:x:1001:1001:John Doe:/home/john:/bin/bash
List Users with compgen
On Bash systems, you can use compgen to list users:
compgen -u
This shows all usernames known to the shell, similar to listing from /etc/passwd.
Conclusion
Whether you are using Ubuntu or another Linux distribution, knowing how to list users is a fundamental administrative skill. You can rely on /etc/passwd, the getent command and tools like cut, awk and compgen to explore and filter users. For real-time monitoring, tools like who, w and users help track logged-in accounts.
By mastering these commands, you will be well-equipped to manage user accounts securely and efficiently. Whether you are scripting automation tasks or maintaining server access, being able to list users in Linux is a key part of system administration.
Brains win battles. Power wins wars. Our servers give you both.
Cores
RAM
Storage
Location
Monthly Price
Link
AMD Opteron 3365 2.3GHz 8c/8t
16 GB DDR3
2x 1 TB (HDD SATA)
Dusseldorf, Germany
$30.95 /month
Buy Now
Intel Atom C2750 2.4 GHz 8 cores
16GB DDR3
1 x 1TB HDD
Paris, France
$34.99 /month
Buy Now
Intel Xeon D-1531 2.2GHz 6c/12t
32 GB DDR4
2x 256 GB (SSD SATA)
Paris, France
$44.50 /month
Buy Now
Intel Core i7-4790K 4GHz 4c/8t
32 GB DDR3
2x 1 TB (HDD SATA)
Dusseldorf, Germany
$48.95 /month
Buy Now
Intel Xeon E3-1220 v2 or better 3.1 GHz 4c/4t
32 GB DDR3
2× 1 TB (SSD SATA)
Amsterdam, Netherlands
$56.95 /month
Buy Now
Intel X5670 2.93 GHZ - 12 Cores / 24 Threads
16GB DDR3
1 x 240 GB SSD
Florida
$74.99 /month
Buy Now
Muhammad Osama
Featured Post
How to Use SCP Command to Securely Transfer Files?
Table of Contents What is SCP? Why Use SCP? Basic Secure Copy Protocol Syntax Transferring Files Using Secure Copy Protocol 1. Copying a File from Local […]
How To Fix cPanel Access Issues?
Table of Contents How To Fix cPanel Access Issues? 1. Verify Your Internet Connection 2. Confirm the Correct cPanel URL 3. Clear Browser Cache and Cookies […]
Prep Command in Linux: All You Need To Know
Table of Contents Prep Command in Linux Basic Syntax Commonly Used Options Practical Examples Combining with Other Commands Prep Command in Linux Basic Syntax The general […]



