Managing users is an essential part of Linux system administration. Knowing how to list all users helps you monitor system access, manage permissions, and ensure security. In Linux, user information is stored in specific system files, and several commands can be used to view this data.
/etc/passwd
FileAll local users are recorded in the /etc/passwd
file. To list them, use:
cat /etc/passwd
Each line in the output represents a user account, including both system and human users. The first field before the colon :
is the username. To view only usernames, run:
cut -d: -f1 /etc/passwd
getent
Commandgetent
retrieves entries from administrative databases, including user data. It’s a more flexible method that also includes users managed via network services like LDAP.
getent passwd
To display only the usernames:
getent passwd | cut -d: -f1
If you need to see currently active users, use:
who
or
w
These commands display who is logged in, their login time, and what they are doing.
compgen
CommandThe compgen
command quickly lists all users and groups:
compgen -u
It outputs a simple list of usernames, making it easy to scan through accounts.
To list all groups, use:
getent group | cut -d: -f1
To verify if a root user exists:
grep root /etc/passwd
Knowing how to list users in Linux helps you audit accounts and maintain secure access control. Whether through /etc/passwd
, getent
, or compgen
, these commands are reliable for system management and troubleshooting.
Linux offers powerful command-line tools for system administrators to view and manage user accounts. Knowing…
User management is a critical aspect of Linux administration. Each user in a Linux system…
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…