How to List All Users in a Linux System: 5 Quick Methods

In terms of Linux system administration activities, user management is considered a crucial aspect. Moreover, knowing the methods to list all users in a Linux system is a highly desired and valuable skill.

Today, we’ll show you various methods to list users on your Linux system, ensuring you know how to manage user accounts effectively.

How to List All Users in Linux?

Listing users in a Linux system is a task that can be accomplished with various commands.

To list all users and their details, follow these methods:

Method 1: Using cat Command

The most straightforward method to list all users is by displaying the contents of the /etc/passwd file. This file comprises one line for each user account which display essential details like:

  • Username
  • User ID (UID),
  • Group ID (GID),
  • Home directory
  • Login shell, etc.

To view the entire list of users, use the cat command by mentioning the /etc/passwd file:

cat /etc/passwd
List All Users in a Linux System Using cat Command

Note: For a more manageable view, especially on systems with numerous users, use the less or more commands.

Method 2: Using awk Command

If you want to list only the usernames without additional details, using the awk command is the easiest way. By specifying the field delimiter and the desired field, you can extract just the usernames:

awk -F':' '{ print $1 }' /etc/passwd
List All Users in a Linux System Using awk Command

Method 3: Using getent Command

The getent command is another powerful tool that queries system databases, including the user accounts database.

To list all users with getent, simply type:

getent passwd
List All Users in a Linux System Using getent Command

Note: This command is particularly useful for systems that use a centralized user management system. It lists all users, not just those in the /etc/passwd file.

Method 4: Using compgen Command

For a quick list of all user names without additional details, you can use the compgen command:

compgen -u
List All Users in a Linux System Using compgen Command

Method 5: Using who Command

The who command provides a list of all users currently logged into the system. Additionally, it shows users’s login time, terminal name, and other details as well:

who
List only logged in Users in a Linux System Using who Command

Conclusion

To list all users in a Linux system, use the cat, awk, getent, and compgen command. The cat /etc/passwd command displays the entire file, which includes information for all users. For a more concise list, the awk -F’:’ ‘{ print $1}’ /etc/passwd command can be used to extract just the usernames.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top