How to Monitor Linux User Activity with Built‑In Commands and Auditd
This guide explains how to track Linux user activity and system events using native commands such as who, w, last, ps, ss, journalctl, and the auditd framework, providing step‑by‑step examples and advanced auditing techniques for security and compliance.
Introduction
Monitoring user activity is a crucial part of Linux system security, helping administrators detect issues, trace events, and maintain compliance. The following sections describe several built‑in tools and the auditd framework, each with concrete command examples.
Using who and w Commands
1. View currently logged‑in users
who2. View user activity and system load
wUsing last Command
1. Show login history for all users
last2. Show login history for a specific user
last usernameUsing auditd Auditing Tool
1. Install and start auditd
sudo apt install auditd # Debian/Ubuntu
sudo yum install audit # CentOS/RHEL
sudo systemctl start auditd2. Monitor file access
auditctl -w /path/to/directory -p rwxa3. View audit logs
cat /var/log/audit/audit.logUsing ps Command
1. List processes for all users
ps aux2. List processes for a specific user
ps -u usernameUsing ss and netstat Commands
1. Show all network connections
ss -tuln2. Filter connections for a specific user
ss -tuln | grep usernameUsing journalctl to View System Logs
1. Show the complete system log
journalctl2. Show sudo operations for a specific user
journalctl _COMM=sudo | grep usernameAdvanced Auditing with auditd and ausearch
1. Set an audit rule for sensitive files
auditctl -w /path/to/sensitive/file -p rwa -k sensitive_file_access2. Query audit logs for a user’s access to the sensitive file
ausearch -k sensitive_file_access -sv avc -u usernameSummary
Linux provides a variety of native commands and the powerful auditd framework to monitor user logins, activity, process usage, network connections, and system events. Regularly using tools such as who, w, last, ps, ss, journalctl, auditd, and ausearch helps maintain system security, ensure compliance, and quickly identify potential problems.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
