Course contentsShow
← Security
Lesson 1497 of 3,05230. Operating System Security - MonitoringFree lesson

Process Accounting with psacct

Enabling process accounting, using ac, sa, and lastcomm commands to track user connect time and command execution history.

Process Accounting with psacct

What you'll learn: How to enable process accounting and use psacct tools to track user activity and command execution for security monitoring and forensics.

What is Process Accounting?

Process accounting is like a detailed timesheet for every program that runs on your system. While auditd (covered previously) tracks specific security-relevant events, process accounting automatically records every command execution, who ran it, when, and how much system resources it consumed. Think of it as your system's complete work diary.

The psacct package (also called acct on some distributions) provides this capability, creating a comprehensive audit trail of process activity—invaluable for security investigations, detecting unauthorized access, and understanding what an attacker did after compromise.

Core Components

Enabling Process Accounting

First, install and enable the service:

# Installation varies by distro
sudo apt install acct       # Debian/Ubuntu
sudo yum install psacct     # RHEL/CentOS

# Enable and start
sudo systemctl enable psacct
sudo systemctl start psacct

Key Commands

ac - Shows connect time statistics per user (who was logged in and for how long):

ac              # Total connect time
ac username     # Time for specific user
ac -d           # Daily breakdown

sa - Summarizes command execution statistics:

sa              # Summary of commands run
sa -u           # Per-user statistics
sa -m           # Most frequently used commands

lastcomm - Shows command execution history (the security goldmine):

lastcomm                    # Recent commands
lastcomm username           # Commands by user
lastcomm systemctl          # All uses of specific command

Security Use Cases

Process accounting helps you answer critical questions: Did someone run suspicious privilege escalation commands? What did an attacker execute after gaining access? Which users are running resource-intensive processes?

Key Takeaway: Process accounting with psacct provides comprehensive command execution tracking through ac, sa, and lastcomm, creating an invaluable audit trail for security monitoring and incident response.