Kahibaro
Discord Login Register

Traditional logs in /var/log

Role of `/var/log` in Traditional Logging

On most Linux systems, /var/log is the central directory where traditional (non-journald) log files are stored. Even on systemd-based systems that primarily use journald, many services still write text logs here, either directly or via a classic syslog daemon (rsyslog, syslog-ng, etc.).

In this chapter, the focus is on:

General concepts of logging and auditing, and systemd’s journal, are covered in their own chapters; here we stay at the level of concrete files.

Layout and Conventions in `/var/log`

While exact contents vary by distribution, some conventions are common:

Common file naming patterns:

Example listing:

$ ls /var/log
alternatives.log  auth.log     dmesg          kern.log
apt/              boot.log     dpkg.log       syslog
journal/          lastlog      wtmp           btmp
nginx/            samba/       Xorg.0.log     ...

Many of these are created and managed by package-specific configuration; not every system will have all of them.

Core System Logs

`/var/log/syslog` and `/var/log/messages`

These are general-purpose system logs used by many distributions, but there are differences:

Both contain a large variety of messages:

Example lines from /var/log/syslog:

Jan 10 09:12:34 host1 NetworkManager[742]: <info>  [1641805954.1234] device (wlp2s0): state change: ...
Jan 10 09:12:35 host1 CRON[10234]: (root) CMD (/usr/local/bin/backup.sh)
Jan 10 09:12:36 host1 kernel: [12345.678901] usb 1-1: new high-speed USB device number 5 using xhci_hcd

Key columns to recognize:

Typical uses:

Basic viewing:

`/var/log/kern.log`

On some distributions (especially Debian-based), kernel messages are separated to /var/log/kern.log in addition to being visible via dmesg.

Typical content:

Example entries:

Jan 10 09:12:36 host1 kernel: [12345.678901] ata1.00: status: { DRDY ERR }
Jan 10 09:12:36 host1 kernel: [12345.678902] e1000e 0000:00:19.0 eth0: Link is Up 1000 Mbps, Full Duplex

Use cases:

Boot and Startup Logs

`/var/log/boot.log`

On systems using bootlogd or similar mechanisms, /var/log/boot.log stores messages from the early boot sequence.

Features:

Example:

* Starting system log daemon rsyslogd                                    [ OK ]
* Starting OpenBSD Secure Shell server sshd                              [ OK ]
* Starting web server apache2                                            [fail]

Use cases:

`/var/log/dmesg` (if present)

Some systems store the boot-time kernel ring buffer into /var/log/dmesg. This is a snapshot similar to the output of dmesg shortly after boot.

Useful for:

Authentication and Security Logs

`/var/log/auth.log` (Debian/Ubuntu) and `/var/log/secure` (RHEL/Fedora)

These files track authentication-related events and security-sensitive actions.

They typically include:

Example (auth.log):

Jan 10 10:01:23 host1 sshd[2123]: Failed password for invalid user admin from 203.0.113.5 port 45678 ssh2
Jan 10 10:01:26 host1 sshd[2123]: Accepted password for alice from 203.0.113.5 port 45678 ssh2
Jan 10 10:02:00 host1 sudo:  alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/bin/systemctl restart nginx

Use cases:

Practical commands:

  sudo tail -n 100 /var/log/auth.log
  sudo grep "Failed password" /var/log/auth.log

`/var/log/faillog` and related files

Some distributions use database-like log files to track failed logins:

These are typically not plain text. Use commands like faillog to read them:

sudo faillog -a

Login History Logs: `wtmp`, `btmp`, `lastlog`

These special files keep historical data about login activity. They’re binary and require specific tools.

`/var/log/wtmp`

Tracks user login and logout events, plus system boots and shutdowns.

To read it:

  $ last
  alice   pts/0        203.0.113.5     Mon Jan 10 10:01   still logged in
  bob     pts/1        203.0.113.10    Mon Jan 10 09:30 - 10:00  (00:30)
  reboot  system boot  5.10.0-10-amd64 Mon Jan 10 09:00   still running

Uses:

`/var/log/btmp`

Tracks failed login attempts. It’s also binary.

To read it:

sudo lastb

Example:

root    ssh:notty    203.0.113.5      Mon Jan 10 10:01 - 10:01  (00:00)

Useful for:

`/var/log/lastlog`

Stores the most recent login time for each user account.

To read:

sudo lastlog

Example:

Username  Port     From             Latest
root      pts/0    203.0.113.5      Mon Jan 10 10:01:26 +0000 2025
alice     pts/1    192.0.2.15       Sun Jan  9 18:12:10 +0000 2025

Use cases:

Package and System Management Logs

`/var/log/apt/` (Debian/Ubuntu)

APT’s subdirectory with logs such as:

Example history.log snippet:

Start-Date: 2025-01-10  10:20:00
Commandline: apt-get install nginx
Install: nginx:amd64 (1.18.0-0ubuntu1)
End-Date: 2025-01-10  10:20:05

Useful for:

`/var/log/dpkg.log` (Debian/Ubuntu)

Lower-level log for the dpkg package manager. Contains detailed records of package installation/removal/configure operations.

Example:

2025-01-10 10:20:01 install nginx:amd64 <none> 1.18.0-0ubuntu1
2025-01-10 10:20:02 status installed nginx:amd64 1.18.0-0ubuntu1

`/var/log/yum.log` or `/var/log/dnf.log` (RHEL/Fedora-based)

Equivalent logs for RPM-based systems, tracking actions by yum or dnf.

Use:

Service-Specific Logs Under `/var/log`

Many services create their own subdirectories under /var/log. Some common examples:

Web Server Logs

Apache HTTP Server: `/var/log/apache2/` (Debian/Ubuntu) or `/var/log/httpd/` (RHEL/Fedora)

Typical files:

Example access.log line:

203.0.113.10 - - [10/Jan/2025:10:30:45 +0000] "GET /index.html HTTP/1.1" 200 1024 "-" "Mozilla/5.0 ..."

Uses:

Nginx: `/var/log/nginx/`

Similar structure:

Application and Service Logs

Other typical service directories:

Each application’s own documentation or configuration (often in /etc/) will define the exact log file names and formats.

Log Rotation and Archived Logs

Traditional text logs in /var/log can grow quickly. logrotate (described in another chapter) manages their size and retention, but you should recognize rotated logs:

Common patterns:

Important points:

  sudo zless /var/log/syslog.2.gz
  sudo zgrep "nginx" /var/log/syslog.3.gz

Typical workflow:

  1. Look at current log:
   sudo tail -n 50 /var/log/auth.log
  1. If the time range you need is older, move to rotated logs:
   sudo zgrep "Jan  9" /var/log/auth.log.1.gz

Practical Troubleshooting Workflows with `/var/log`

Here are some focused examples of how /var/log is used in day-to-day work.

Checking for Failed SSH Logins

# Recent failed SSH logins (Debian/Ubuntu)
sudo grep "Failed password" /var/log/auth.log | tail
# On RHEL/Fedora
sudo grep "Failed password" /var/log/secure | tail

Finding Why a Service Failed to Start (Traditional Logging)

If a service logs via syslog and not only via systemd’s journal:

sudo grep nginx /var/log/syslog | tail
# or
sudo grep nginx /var/log/messages | tail

Then pivot to /var/log/nginx/error.log for more details.

Tracing a System Change to a Package Update

# See what was changed around the time of the problem (Debian/Ubuntu)
sudo less /var/log/apt/history.log
sudo less /var/log/dpkg.log
# On RHEL/Fedora
sudo less /var/log/dnf.log

Investigating a Suspected Hardware Issue

# Check kernel messages related to disks, filesystems, etc.
sudo less /var/log/kern.log     # if present
# or search within syslog/messages
sudo grep -i "error" /var/log/syslog | tail

Look for patterns like I/O errors, resets, or repeated warnings.

Permissions and Access Considerations

Because logs often contain sensitive information, many files in /var/log are:

Typical permissions:

-rw-r----- 1 root adm  12345 Jan 10 10:35 auth.log
-rw-r----- 1 root adm  67890 Jan 10 10:35 syslog

Implications:

  sudo less /var/log/auth.log

Summary

Traditional logs in /var/log remain crucial even on modern, systemd-based systems:

Being effective with /var/log is about:

Views: 20

Comments

Please login to add a comment.

Don't have an account? Register now!