Dedicated servers with AMD EPYC™ 9254 and 9554 processors are now available in our stock. Click here to order.

Блог

Linux List Users: How to Display All Users in the Terminal?

  • Понедельник, Август 25, 2025

Listing users in a Linux system is an important administrative task. This task becomes considerably more necessary and helpful when multiple individuals are working on the same machine. It allows efficient system administration and helps in monitoring who has access.

Linux has several commands for displaying users, such as cat, getent, awk, and cut. Each command serves different use cases, from printing all user details to extracting only usernames. This article explains how to list users in Linux using different commands and covers prerequisites, command walkthroughs, best practices, and automation tips.

Prerequisites for Listing Linux Users

Before you begin listing users on a Linux system, there are a few important things you need to have in place.

  • Have terminal access: For local machines, open the Terminal. Use web-based terminals or SSH programs like PuTTY or Linux/macOS Terminal to connect to distant systems like a VPS.

  • Log in with proper privileges: Admin access may be needed for some tasks to work properly. Therefore, using your normal user account to execute those commands with sudo is preferable to logging in as root. This method keeps your system safer and more secure.

Understanding Linux User Accounts

Linux distinguishes between two main types of users:

  • System users: Created automatically during OS or service installation. Their user IDs usually range from 1-999.

  • Normal users: Created manually using tools like “useradd”. Their UIDs usually start from 1000 and above.

The /etc/passwd file keeps all user account information. Each line represents one user and follows the format below.

username:x:UID:GID:user_info:/home/username:/bin/bash

 

Line Structure Explained:

  • username - Account name

  • x - Placeholder for the password

  • UID - User ID

  • GID - Group ID

  • user_info - Optional description

  • /home/username - Home directory path

  • /bin/bash - Default shell

How to List Users in Linux

Users from the terminal can be displayed in a variety of ways. Various techniques offer varying degrees of specificity and are beneficial based on your objective.

1. Using the cat Command

The cat command reads and prints file contents. You can use it to display all user accounts by showing the /etc/passwd file:

cat /etc/passwd

1.png

This will print each line representing a user. You’ll see both system and normal users, along with their UID, home directory, and default shell. Also, to list only logged-in users, you can use the “users” command.

2. Using the getent Command

The getent command is a simple way to get user information from system databases controlled by the /etc/nsswitch.conf file. It’s mostly used on systems where user accounts are shared across a network.

To list all users:

getent passwd

To get details for a specific user:

getent passwd username

This command provides similar output to cat /etc/passwd but respects all system-defined sources, not simply local files.

3. Using awk and cut for Custom Output

If you only want usernames without other data, use awk or cut.

Using awk:

awk -F':' '{ print $1 }' /etc/passwd

2.png

This requires awk to use “:” as a delimiter and print the first field, which is the username.

Using cut:

cut -d: -f1 /etc/passwd

3.png

This produces the same output.

Print other fields like User IDs:

awk -F':' '{ print $3 }' /etc/passwd

or

cut -d: -f3 /etc/passwd

These commands are useful when you're scripting or auditing specific aspects of users.

Best Practices for Effective User Listing

It is recommended that you follow certain best practices that might improve your security and productivity in order to get the most out of listing users in Linux.

1. Use Pipes for Advanced Filtering

Linux pipes (|) let you connect commands to filter and process output.

Example:- Check if a user exists

cat /etc/passwd | grep johndoe

 

If the output includes a line, the user exists.

Example: Find all users who own files

find / -type f -exec stat -c "%U %n" {} + 2>/dev/null | awk '{print $1}' | sort -u

This finds all file owners and lists them uniquely.

2. Use GUI Tools 

For users uncomfortable with command-line tools, GUI-based user managers can be helpful.

Popular Linux Control Panels:

  • Webmin

  • Virtualmin

  • Plesk

These help you to list, create, or modify users via web interfaces. 

3. Manage User Information Securely

Proper user management helps maintain data safety and system integrity.

  • In order to maintain minimal privileges, provide sudo rights only when required.

  • Set appropriate file permissions to restrict usage of important directories.

  • Enforce strong and complex passwords through clear password policies.

4. Automate with Bash Scripts

Instead of running commands manually, use bash scripts to automate tasks like generating a user list or auditing accounts.

Example script to list users:

#!/bin/bash
awk -F':' '{ print $1 }' /etc/passwd > /home/admin/user_list.txt

Schedule this script using cron to run periodically:

crontab -e

Add:

0 0 * * 1 /path/to/script.sh

This will run the script every Monday at midnight.

Platforms with built-in assistants can help generate bash scripts for your needs directly from the dashboard.

Conclusion

One of the most basic skills of system administration in Linux is the ability to list users. You can gather and examine user data with programs like cat, getent, awk, and cut. These tools are helpful if your server is local or remote.

You can modify outputs with awk and cut, but for full details, use cat or getent. Use pipes to combine commands for more advanced filtering, and think about using GUI tools or bash scripts for automation and convenience.

Lastly, always put secure user management first. Reduce the amount of access users require and frequently review their work. These methods simplify your job and help you maintain the security and organization of your Linux system.

If you’re looking for a reliable VPS to practice and apply these skills, Bacloud is a strong option. They offer affordable plans and flexible configurations that are ideal for Linux system administration. It’s a good fit whether you’re starting out or managing production environments.

FAQ

« Назад