Monitoring logged-in users is essential for system administrators and developers working on Linux. The Linux users command provides a quick and straightforward way to check active user sessions, making it a handy tool for managing multi-user systems.
In this guide, we’ll explore the Linux users command, compare it with who
, and demonstrate practical use cases, including automation for security monitoring.
📺 For a step-by-step visual guide, watch this video:
What is the Linux Users Command?
The Linux users command is a simple yet effective tool that displays a list of all users currently logged into the system. Unlike more detailed commands, users
provides a concise overview, making it useful for quick monitoring.
Why is This Important?
✅ Quickly check who is logged in on a shared server.
✅ Detect unauthorized access or suspicious activity.
✅ Ensure no critical sessions are active before restarting services.
Let’s see it in action:
users
Example Output:
adminuser
Here, adminuser
represents an active session. If the same user logs in multiple times, their name appears multiple times in the output.
Real-World Scenario: Monitoring User Sessions
Imagine you’re a system administrator managing a Linux server. You need to check if multiple users are logged in before performing maintenance. Instead of running complex commands, a simple Linux users command gives a quick overview.
Additionally, this command can help spot anomalies, such as unauthorized user sessions. If you notice unknown usernames, it might indicate a security breach.
Linux Users Command vs. who
Command: What’s the Difference?
While the Linux users command provides a minimal list of logged-in users, the who
command offers more details, including login terminals and timestamps.
Example Usage:
who
Example Output:
john pts/0 2025-01-01 10:32 (192.168.1.100)
doe pts/1 2025-01-01 10:35 (192.168.1.101)
admin pts/2 2025-01-01 10:37 (localhost)
✅ Use who
for detailed session tracking.
✅ Use the Linux users command for a quick overview.
Both commands are useful, depending on your needs.
Combining the Linux Users Command with Other Commands
To extend its functionality, you can combine the Linux users command with other Linux tools.
Counting Logged-In Users
To count the number of logged-in users, use the following command:
users | wc -w
Example Output:
2
✅ Useful for monitoring multi-user environments.
✅ Helps in tracking system load and resource usage.
Automating User Monitoring with Scripts
System administrators can automate user monitoring with scripts to enhance security.
if [[ $(users) == *"unknown_user"* ]]; then
echo "Alert: Unknown user logged in!" | mail -s "Login Alert" admin@example.com
fi
✅ This script automatically detects unauthorized users and sends an email alert.
✅ Helps secure shared servers and prevents unauthorized access.
FAQs
1. What does the Linux users command do?
The Linux users command displays a list of all currently logged-in users on a Linux system.
2. How is the Linux users command different from who
?
The Linux users command shows only usernames, while who
provides detailed session information, including login terminals and timestamps.
3. Can I use the users command in scripts?
Yes, it can be used in scripts for monitoring and automation, such as triggering alerts for unauthorized logins.
4. How do I count the number of logged-in users?
Use users | wc -w
to count the number of logged-in users.
5. Is the users command available on all Linux distributions?
Yes, the Linux users command is a standard command available on most Linux distributions, including Rocky Linux, Ubuntu, and CentOS.
Conclusion
The Linux users command is a powerful yet simple tool for monitoring logged-in users on a Linux system. Whether you’re managing a shared server, tracking activity, or securing your system, this command proves to be an invaluable asset.
📺 For a hands-on tutorial, watch this video.
Want to learn more Linux commands? Check out our other guides on system administration.