Open In App

How to Access All Users in Linux Using Different Commands?

Last Updated : 08 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Linux allows multiple users with their own custom setting and configuration to work together on the same system, even at the same time. It can even allow a particular user to access several sessions from different locations in order to work on the system. Below is a list of different commands to access the list of users in Linux:

Methods to Access All Users in Linux

Here are the various methods by which we can access all users in Linux.

1. less command

In less command, each local user's information is stored in the "/etc/passwd/" file, where each line in the file represents login information for one user. less command extracts user information from that file.

Syntax:

less /etc/passwd

Example:using less command in Linux

The /etc/passwd file is the core database for all local users on a Linux system. Each entry contains 7 colon-separated fields:

  1. Username (e.g., anshu)
  2. Password placeholder (x indicates encrypted passwords are stored in /etc/shadow).
  3. User ID (UID) â€“ Unique identifier (e.g., 1000 for regular users, 0 for root).
  4. Group ID (GID) â€“ Primary group identifier.
  5. GECOS â€“ Optional user description (e.g., full name).
  6. Home directory (e.g., /home/anshu).
  7. Login shell (e.g., /bin/bash).

2. getent command

getent command fetches user information from database configured in /etc/nsswitch.conf. file which also includes passwd database. Syntax:

getent passwd

Example:

getent-command-copy-2
  • Lists all users, including those from external directories.
  • Essential for debugging authentication issues in networked environments.

3. awk or cut command

If only username is what you want, use awk or cut commands to print only the field containing the username.

Syntax:

awk -F: '{print$1}' /etc/passwd
cut -d: -f1 /etc/passwd
getent passwd | awk -F: '{print$1}'
getent passwd | cut -d: -f1

Example:using awk commandusing cut command

4. compgen command:

compgen command also displays the name of all the users without any additional information.

Syntax:

compgen -u

Example:compgen command in Linux

Note: One can use compgen -c command to list all commands available if he/she is not the admin on a Linux system and don't have the sudo access.

5. who command

who command will print the info of the currently logged in user.

Syntax:

who

Example:using who command in Linux

6. wc Command

wc command will get the total number of users on a particular linux system.

Syntax:

getent passwd |wc -l

Example:

using wc command to find all the users in Linux System

Conclusion

Linux is a multi-user operating system that allows multiple users to work on the same system simultaneously, each with their own custom settings and configurations. Whether you need to list all users, find specific usernames, or check logged-in users, Linux provides multiple commands like less, getent, awk, cut, compgen, who, and wc to retrieve user-related information.

Each command serves a different purpose—from displaying all system users (less /etc/passwd), fetching users from databases (getent passwd), extracting usernames (awk, cut), listing users (compgen -u), checking active users (who), to counting total users (wc -l).

Also Read: 25 Basic Linux Commands For Beginners [2025]by


Next Article

Similar Reads