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:
usernameis the username of the userpasswordis an encrypted representation of the user’s password (often set toxor*to indicate that the password is stored in another database, such as/etc/shadow)UIDis the user ID numberGIDis the group ID numberGECOSis a field that contains additional information about the user, such as their full namehome_directoryis the user’s home directoryshellis 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.