Linux List All Users In The System Command

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 user
  • password is an encrypted representation of the user’s password (often set to x or * to indicate that the password is stored in another database, such as /etc/shadow)
  • UID is the user ID number
  • GID is the group ID number
  • GECOS is a field that contains additional information about the user, such as their full name
  • home_directory is the user’s home directory
  • shell 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.

Leave a Comment