System
Difficulty: Beginner
3 min read

Acct: Process Accounting on Linux

Complete guide to installing and configuring acct (GNU Accounting Tool) to monitor and record process usage on a Linux system.

Back to tutorials
What is acct?
The acct (or psacct) tool records the activity of every process on the system, providing detailed information about the commands executed, the user, the CPU time, and the time of execution. It is an invaluable tool for auditing and monitoring.

Why Use acct?

  • Security Auditing: Full traceability of executed commands, useful for post-incident investigations.
  • Resource Tracking: Analysis of CPU and memory consumption per user or per process.
  • Activity Monitoring: Visibility into the activity of users and system services.

Prerequisites

  • Operating system: A Linux distribution (Debian, Ubuntu, CentOS, RHEL).
  • Privileges: Root access or sudo privileges.

Installing acct

Step 1: Installing the package

The package name varies depending on the distribution:

# For Debian / Ubuntu
sudo apt-get update
sudo apt-get install -y acct

# For CentOS / RHEL
sudo yum install -y psacct

Step 2: Enabling the service

Once installed, the service must be enabled and started:

sudo systemctl start acct
sudo systemctl enable acct
# On CentOS/RHEL, the service is named psacct
sudo systemctl start psacct
sudo systemctl enable psacct

Verify that the service is indeed active:

sudo systemctl status acct # or psacct
Service enabled
The acct service is now running and recording process activity.

Main acct commands

Several commands let you make use of the collected data.

lastcomm: Most recently executed commands

Displays the list of executed commands, from the most recent to the oldest.

lastcomm

To filter by user or by command:

# Commands executed by the user 'morgann'
lastcomm morgann

# All executions of the 'ls' command
lastcomm ls

sa: Summary per command

The sa command provides a summary of the collected information, aggregated by command.

# Basic summary
sa

# Sort by the number of calls
sa -n

# Display information per user
sa -m

ac: Connection time per user

Displays the total connection time of users in hours.

# Total time per user
ac -p

# Total time for all users
ac

Log Files and Rotation

The data is stored by default in /var/log/account/pacct. This file can grow quickly.

Configuring rotation

It is crucial to set up log rotation with logrotate. Create a /etc/logrotate.d/acct file:

sudo nano /etc/logrotate.d/acct

File contents:

/var/log/account/pacct {
    weekly
    rotate 4
    compress
    missingok
    notifempty
    create 0644 root root
}
Managing disk space
Without rotation, the acct log file can fill up your root partition. Do not skip this step!

Conclusion

The acct or psacct tool is an excellent way to strengthen the security and monitoring of your Linux systems. It provides essential traceability for auditing and performance analysis. Its installation and configuration are simple, but do not forget to manage its log rotation for worry-free use in production.

Written by

Morgann Riu

Cybersecurity and Linux administration expert. I share my knowledge through free tutorials and training to help system administrators and developers secure their infrastructures.

Frequently asked questions

Why does systemctl start acct fail on CentOS or RHEL?
On RHEL-family distributions, the package and the systemd unit are named psacct, not acct. Install it with sudo yum install -y psacct, then run sudo systemctl start psacct and sudo systemctl enable psacct. On Debian and Ubuntu it really is acct in both cases.
What is the difference between lastcomm, sa and ac?
lastcomm lists executed commands one by one, from the most recent to the oldest, and accepts a filter: lastcomm morgann for a user, lastcomm ls for a specific command. sa aggregates that same data per command, with sa -n to sort by number of calls and sa -m to break it down per user. ac is not about processes at all but about connection time in hours, with ac -p giving the per-user breakdown.
lastcomm returns nothing, where should I look?
First check that the service is actually running with sudo systemctl status acct (or psacct): as long as it is not started, nothing is collected. Then check that /var/log/account/pacct exists and has a non-zero size, since that is the file lastcomm actually reads. A missing or empty file means process accounting was never active.
My root partition filled up after installing acct, what now?
The /var/log/account/pacct file records every process and grows without limit as long as no rotation is in place. Create /etc/logrotate.d/acct with a policy along the lines of weekly, rotate 4, compress, missingok, notifempty and create 0644 root root. This is the most commonly skipped step, and exactly the one that fills the disk in production.
Is acct enough on its own for a security audit?
It gives you traceability of the commands executed, along with the associated user, CPU time and time of execution, which already covers the core of a post-incident investigation and per-user or per-process resource tracking. It stays process-centric, though, and does not replace auditing of file access. And since the journal is purely local, plan for log shipping if you want it to survive a compromise of the machine.

Share this tutorial

Did you enjoy this article?

Comments

Checklist Sécurité Linux

30 points essentiels pour sécuriser un serveur Linux. Recevez aussi les nouveaux tutoriels par email.

Pas de spam. Désabonnement en 1 clic.