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/passwdEach 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/passwdgetent 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 passwdTo display only the usernames:
getent passwd | cut -d: -f1If you need to see currently active users, use:
whoor
wThese 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 -uIt outputs a simple list of usernames, making it easy to scan through accounts.
To list all groups, use:
getent group | cut -d: -f1To verify if a root user exists:
grep root /etc/passwdKnowing 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.
Setting up Apache Ubuntu 26.04 is one of the fastest ways to launch a reliable…
Setting up a Static IP on Ubuntu configuration is essential for servers, remote access systems,…
Keeping the correct system clock is important for servers, desktop systems, scheduled tasks, and application…
An Ubuntu Hostname Change is a common administrative task used to rename Linux servers, desktops,…
Ubuntu Swap Space helps Linux systems stay responsive when physical RAM starts running low. Instead…
If you need secure remote desktop access on Linux, learning how to Install TeamViewer on…