Linux

How to List Users in Linux

Managing users is an essential part of Linux system administration. Knowing how to list all users helps you monitor system access, manage permissions, and ensure security. In Linux, user information is stored in specific system files, and several commands can be used to view this data.

Check Users from the /etc/passwd File

All local users are recorded in the /etc/passwd file. To list them, use:

cat /etc/passwd

Each line in the output represents a user account, including both system and human users. The first field before the colon : is the username. To view only usernames, run:

cut -d: -f1 /etc/passwd

Using the getent Command

getent retrieves entries from administrative databases, including user data. It’s a more flexible method that also includes users managed via network services like LDAP.

getent passwd

To display only the usernames:

getent passwd | cut -d: -f1

Listing Logged-In Users

If you need to see currently active users, use:

who

or

w

These commands display who is logged in, their login time, and what they are doing.

Using compgen Command

The compgen command quickly lists all users and groups:

compgen -u

It outputs a simple list of usernames, making it easy to scan through accounts.

View Groups and Root User

To list all groups, use:

getent group | cut -d: -f1

To verify if a root user exists:

grep root /etc/passwd

Conclusion

Knowing how to list users in Linux helps you audit accounts and maintain secure access control. Whether through /etc/passwd, getent, or compgen, these commands are reliable for system management and troubleshooting.

0xSnow

0xSnow is a cybersecurity researcher with a focus on both offensive and defensive security. Working with ethical hacking, threat detection, Linux tools, and adversary simulation, 0xSnow explores vulnerabilities, attack chains, and mitigation strategies. Passionate about OSINT, malware analysis, and red/blue team tactics, 0xSnow shares detailed research, technical walkthroughs, and security tool insights to support the infosec community.

Recent Posts

Install Apache Cassandra on Ubuntu 18.04: NoSQL Setup Guide

Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with…

30 minutes ago

Install Rocket.Chat on Ubuntu 18.04 with Nginx and Let’s Encrypt

Rocket.Chat is a free, open-source team communication platform built with the Meteor framework. It is a…

35 minutes ago

Install MySQL on Ubuntu 18.04: Setup, Security, and Root Access

MySQL is the most popular open-source relational database management system. It is fast, reliable, and scales…

39 minutes ago

Install Apache on Ubuntu 18.04: Web Server Setup and Config

Apache is the most widely used web server in the world. It is free, open-source, and…

43 minutes ago

Install NetBeans IDE on Ubuntu 18.04 with Snap and OpenJDK 8

NetBeans is a free, open-source, cross-platform IDE developed by the Apache Software Foundation. It was one…

48 minutes ago

Install Pip on Ubuntu 18.04: Python 3 and Python 2 Setup Guide

Pip is the official package manager for Python and the standard way to install libraries from…

5 days ago