Linux offers powerful command-line tools for system administrators to view and manage user accounts. Knowing how to list users efficiently helps you audit your system, monitor access, and ensure proper security configurations.
/etc/passwd
FileAll user information is stored in the /etc/passwd
file. You can display the file content using:
cat /etc/passwd
Each line represents a single user account, containing details like username, UID, GID, home directory, and shell. To extract only usernames, use:
cut -d: -f1 /etc/passwd
This provides a simple list of all users on the system.
getent
CommandThe getent
command retrieves entries from administrative databases such as passwd or group. It’s more reliable for systems that use centralized authentication like LDAP.
getent passwd
To show just usernames:
getent passwd | cut -d: -f1
This lists both local and network-based users if the system integrates with directory services.
compgen
CommandFor a quick overview, compgen
is a convenient command:
compgen -u
This outputs all usernames registered on the system. Similarly, to view all groups:
compgen -g
To find which users are actively logged in, use:
who
or
w
These commands show user sessions, terminal activity, and login times.
You can combine commands for better insights. For example, to count total users:
getent passwd | wc -l
This helps administrators track the number of registered accounts.
Mastering command-line techniques for listing users is essential for Linux administrators. Whether using /etc/passwd
, getent
, or compgen
, these commands simplify user auditing and enhance security monitoring.
User management is a critical aspect of Linux administration. Each user in a Linux system…
Managing users is an essential part of Linux system administration. Knowing how to list all…
Nmap (Network Mapper) is a free tool that helps you find devices on a network,…
Introduction to the Model Context Protocol (MCP) The Model Context Protocol (MCP) is an open…
While file extensions in Linux are optional and often misleading, the file command helps decode what a…
The touch command is one of the quickest ways to create new empty files or update timestamps…