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.service2. Standard /var/log Directory Files
| Log File | Contains |
|---|---|
/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 / secure | Authentication logs, SSH logins, and sudo attempts |
/var/log/nginx/ | Web server access.log and error.log |
dmesg | Kernel 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 204. 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.
Linux Networking Commands Reference
Inspect network interfaces with ip, check listening ports with ss, test connectivity with ping and curl, and configure firewalls with ufw.
Linux SSH Configuration & Hardening
Generate Ed25519 SSH keypairs, configure ~/.ssh/config, manage authorized_keys, and harden sshd_config against unauthorized access.