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/passwdEach 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/passwdThis 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 passwdTo show just usernames:
getent passwd | cut -d: -f1This 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 -uThis outputs all usernames registered on the system. Similarly, to view all groups:
compgen -gTo find which users are actively logged in, use:
whoor
wThese 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 -lThis 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.
MySQL is the most popular open-source relational database management system. It is fast, reliable, and a…
Git is the most widely used version control system in the world. It was created by…
Go (also called Golang) is an open-source programming language built by Google. It is designed to…
Visual Studio Code (VS Code) is an open-source code editor developed by Microsoft. It is one…
Nginx (pronounced "engine x") is an open-source, high-performance web server and reverse proxy. It is used…
Apache is one of the most widely used open-source web servers in the world. It is…