You can use the getent
command to list all the users in a Linux system. The getent
command retrieves entries from various administrative database sources, including the password database which stores information about the users on the system.
Here’s an example of how to use the getent
command to list all the users in the system:
getent passwd
The passwd
argument specifies that we want to retrieve information from the password database.
This will produce output that lists all the users in the system, one user per line, in the format:
username:password:UID:GID:GECOS:home_directory:shell
Where:
username
is the username of the userpassword
is an encrypted representation of the user’s password (often set tox
or*
to indicate that the password is stored in another database, such as/etc/shadow
)UID
is the user ID numberGID
is the group ID numberGECOS
is a field that contains additional information about the user, such as their full namehome_directory
is the user’s home directoryshell
is the user’s default shell
You can also use the cut
command to extract specific columns from the output and format it as needed:
getent passwd | cut -d: -f1
This will list only the usernames of all the users in the system.