Linux log files: where they are and what they record
Linux log files are plain-text or binary records that the kernel, system services and applications write, mostly under /var/log. For an investigator they hold the logons, commands, service changes, package installs and network activity that reconstruct what happened on a server. Which files exist depends on the distribution and on whether the system logs through rsyslog, the systemd journal or both, so the first step on any host is to see what is there.
The main log files
| File | Distributions | What it records | Why it matters in an investigation |
|---|---|---|---|
/var/log/auth.log | Debian, Ubuntu | Authentication: SSH logins and failures, sudo, su, PAM sessions, user and group changes | Who got in, from where, and who became root. See syslog and sudo log |
/var/log/secure | RHEL, CentOS, Rocky, Alma, Fedora | The same as auth.log on Red Hat family systems | As above |
/var/log/syslog | Debian, Ubuntu | General system messages from most services | Service starts and failures, cron runs, kernel messages, application errors around the incident |
/var/log/messages | Red Hat family, SUSE | General system messages | As syslog |
/var/log/journal/ | systemd systems (most current distributions) | The binary systemd journal: every service's output with metadata | Often the only full record on minimal systems; survives where text logs are not configured. See systemd journal |
/var/log/audit/audit.log | Systems running auditd | Kernel audit events: executed commands (execve), file access, logins, configuration changes, depending on the rules | The closest thing to process creation logging on Linux. See auditd |
/var/log/wtmp, btmp, lastlog | Most distributions | Binary login records: logins and logouts, failed logins, last login per user | Login history, read with last and lastb. See wtmp, btmp and utmp |
/var/log/cron or cron lines in syslog | Varies | Scheduled job runs | Persistence through cron. See cron |
/var/log/apt/history.log, dpkg.log | Debian, Ubuntu | Package installs and removals, with the command that ran them | Tools an attacker installed. See APT history |
/var/log/dnf.log, yum.log | Red Hat family | Package transactions | As above. See DNF history |
/var/log/nginx/, /var/log/apache2/ or httpd/ | Web servers | Access and error logs: every request with client address, URL, status and user agent | Exploits, web shells and data pulled over HTTP. See nginx and Apache |
/var/log/kern.log, dmesg | Most | Kernel messages | Kernel modules loaded (rootkits), USB devices, firewall drops if logged |
Logs rotate: logrotate renames old files (auth.log.1, auth.log.2.gz) and deletes the oldest, usually after four weeks to a few months. Collect the rotated and compressed copies too, and check how far back each log goes before concluding that something did not happen.
Beyond the log files
Many of the most useful Linux artifacts are not logs. Shell history files keep the commands typed in interactive shells; authorized_keys files show which keys can log in as each user (a favourite backdoor); crontabs and systemd units hold persistence; /etc/passwd, /etc/shadow and /etc/sudoers show accounts and privileges; /etc/ld.so.preload is a known rootkit hook; and file system metadata (inode times) dates when files appeared. Container hosts add Docker configuration and container logs.
Reading Linux logs as an investigator
- Mind the time zone and the year. Traditional syslog lines carry no year and no time zone; they are written in the host's local time. Arcsentry infers the year from the file's rotation and labels host-local times rather than guessing a zone.
- Read auth and journal together. SSH logins appear in auth.log or secure and in the journal; one may have been cleared and not the other.
- Expect gaps where an attacker had root. Root can edit any text log and truncate binary ones. Gaps in time, missing rotations and a modification time later than the last line are signs of tampering.
- Commands are not logged by default. Unless auditd has execve rules, the only command record is shell history, which is easy to delete. That is the main reason to deploy auditd before an incident.
Collecting Linux logs and artifacts
Arcsentry Collector runs as a single static binary on a live Linux host, or reads ext2, ext3 and ext4 file systems straight from a disk image without mounting, and gathers the logs, rotated copies, configuration and user artifacts into one encrypted archive, with live command output (processes, connections, login records) on live hosts. Arcsentry also reads UAC and Velociraptor collections. Each of the 302 Linux artifacts below has its own page with locations, fields and the collection targets that gather it, and the Linux forensics article shows how they fit into one timeline.