How to Access All Users in Linux Using Different Commands?
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
1. 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: Each line above has seven fields separated by colons which contains the following information:
- Username
- Encrypted Password
- User ID number(UID)
- User group ID number(GID)
- Full name of the user(GECOS)
- user home directory and
- Login shell respectively.
2. getent command
This command fetches user information from database configured in /etc/nsswitch.conf. file which also includes passwd database. Syntax:
$getent passwd
Example:

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:
4. compgen command:
This command also displays the name of all the users without any additional information. Syntax:
$compgen -u
Example:
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
This will print the info of the currently logged in user. Syntax:
$who
Example:
6. wc Command
This command will get the total number of users on a particular linux system. Syntax:
$getent passwd |wc -l
Example:
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
).
How to Access All Users in Linux Using Different Commands? – FAQs
How to get all users in Linux command?
To list all users in Linux, you can use multiple Linux commands:
less /etc/passwd
– Displays all users stored in the system.getent passwd
– Fetches user details from the system database.awk -F: '{print $1}' /etc/passwd
orcut -d: -f1 /etc/passwd
– Extracts only usernames.compgen -u
– Lists all system users without extra details.
How do I give access to all users in Linux?
To grant access to all users in Linux, you can modify file permissions or use user group management:
1. Change File Permissions:
- Use
chmod 777 filename
to give read, write, and execute permissions to all users (not recommended for sensitive files).2. Modify User Groups:
usermod -aG groupname username
– Adds a user to a group to provide shared access.chmod g+rwx filename
– Grants group permissions on a file.3. Grant Sudo Access:
- Use
visudo
and add users to sudoers file for admin privileges.
How do I list all login users in Linux?
To check currently logged-in users, use:
who
– Displays all active users.w
– Shows logged-in users with system activity.whoami
– Prints the currently logged-in user.last
– Shows login history for all users.