Linux user management is a fundamental skill for system administrators. One of the essential tasks in this domain is listing users on your Linux system. Knowing how to do this can be incredibly useful for system monitoring, access control, and security. In this guide, we’ll explore various methods to list users in a Linux environment.
Understanding User Management in Linux
Before we dive into user listing, let’s briefly understand user management in Linux.
Linux has two primary types of users:
- Superusers (Root): These users have the highest level of administrative access, often denoted by the username “root.”
- Regular Users: Regular users are standard accounts created for day-to-day activities. They don’t have system-level privileges like the root user.
User accounts are essential for system security and access control. They help you track who can log in and interact with your system. Now, let’s move on to listing these users.
Basic Commands for Listing Users
Here are some basic commands you can use to list users in Linux:
who command displays information about users who are currently logged in, along with details like terminal, login time, and originating IP addresses. To use it, open your terminal and type:
w command provides detailed information about logged-in users, including their terminal, username, activity, and more. It’s an extension of the
who command. To use it:
users command displays a simple list of usernames of users currently logged in. It’s straightforward and useful:
These commands are excellent for seeing who’s currently active on your system. However, they won’t provide a comprehensive list of all users, including those who are not currently logged in.
Listing Local Users
To list all local users on your system, you can use the
/etc/passwd file in combination with command-line tools like
getent. Here’s how you can do it:
cut -d: -f1 /etc/passwd
This command uses the colon (
:) as a delimiter to extract usernames from the
Listing All Users, Including System Users
To list all users, including system users, you can use the
/etc/passwd file along with commands like
cut. Here’s how to do it:
cat /etc/passwd | cut -d: -f1
This command combines the
cut commands to extract all usernames from the
Listing Users from Specific Groups
To list users who belong to specific groups, you can use the
getent command along with
awk. For example, to list users from the “sudo” group:
getent group sudo | cut -d: -f4
This command retrieves the “sudo” group details and extracts the list of users.
Listing Users with Specific Attributes
You can also list users with specific attributes, such as those who haven’t logged in for a certain period. The
chage commands are handy for this purpose.
lastlog command lists users who haven’t logged in. For instance, to list users who haven’t logged in for the past 90 days:
lastlog -b 90
This command displays a list of users and their last login information.
chage command allows you to view and change user password aging information. To list users with aging information:
chage -l username
Replace “username” with the actual username.
Listing Users in a More User-Friendly Format
To present the user list in a more user-friendly format, you can use commands like
column. For example, to format the list as a single column:
cut -d: -f1 /etc/passwd | column
This command utilizes
cut to extract usernames and
column to format them neatly.
Understanding how to list users is a fundamental skill for Linux administrators. It’s a key aspect of system monitoring, access control, and user management. By using the methods and commands outlined in this guide, you can efficiently list users and gain valuable insights into your Linux system.
Remember, user management goes beyond just listing users; it involves creating, modifying, and deleting user accounts, which