Skip to main content
⚡ OpenDevDocs
Linux
linuxlinuxGuideIntermediate

Linux Logs & journalctl Troubleshooting

Inspect Linux system logs, query systemd services with journalctl, filter by time and priority, and manage logrotate.

Verified: 2026-09-30
Tested on:linux Ubuntu 24.04 / Debian 12
Platforms:
linux
#linux#logs#journalctl#troubleshooting#devops

1. Querying systemd Logs with journalctl

journalctl is the centralized log query tool for all systemd services and kernel events.

# Follow logs for a specific service in real time (like tail -f)
sudo journalctl -u my-api.service -f

# View logs from the current boot only
sudo journalctl -u nginx.service -b

# View logs generated within the last 1 hour
sudo journalctl --since "1 hour ago"

# View logs within an exact timestamp window
sudo journalctl --since "2026-10-01 00:00:00" --until "2026-10-01 02:00:00"

# Show only error and critical priority logs
sudo journalctl -p err -u postgresql.service

2. Standard /var/log Directory Files

Log FileContains
/var/log/syslog (Debian/Ubuntu)General system activity and background services
/var/log/messages (RHEL/CentOS)General operating system event messages
/var/log/auth.log / secureAuthentication logs, SSH logins, and sudo attempts
/var/log/nginx/Web server access.log and error.log
dmesgKernel ring buffer messages (hardware, OOM kills, device drivers)

3. Investigating SSH Brute Force Attempts

# View recent failed login attempts
sudo grep "Failed password" /var/log/auth.log | tail -n 20

4. Automatic Log Rotation (logrotate)

Log files are automatically compressed and rotated daily or weekly via /etc/logrotate.conf and /etc/logrotate.d/* to prevent disks from filling up with unbounded text logs.

On this page