Linux Logs Explained: Find Every Suspicious Event With journalctl and grep
Your Linux machine is a compulsive diarist. Every login attempt, every crashed service, every sudo command — written down, timestamped, waiting for you to read it. Logs are the first place defenders look when something goes wrong, and the first place attackers try to erase. Here’s how to read them.
Where Logs Live
Two systems share the job on modern distros:
- journald — the systemd journal. Binary format, queried with journalctl. This is the default on Ubuntu, Debian, Fedora and most modern systems.
- Classic text logs in /var/log/ — syslog, auth.log, kern.log, dmesg output. Still essential, especially auth.log on Debian/Ubuntu (it’s /var/log/secure on RHEL/Fedora).
journalctl: The Essentials
journalctl -u ssh.service # all logs for the SSH servicejournalctl -u ssh.service -f # follow live, like tail -fjournalctl --since "1 hour ago" # everything in the last hourjournalctl -p err --since today # today's errors and worsejournalctl -b # only logs since last boot
The -p flag filters by priority: emerg, alert, crit, err, warning, notice, info, debug. When a service misbehaves, “journalctl -u <service> -p err” is your fastest path to the actual error instead of guessing.
Hunting Failed Logins
This is the single most useful log query for a defender. On Debian/Ubuntu:
sudo grep "Failed password" /var/log/auth.log | tail -20
You’ll see lines like “Failed password for root from 203.0.113.45 port 51234 ssh2”. One or two from your own IP: normal. Hundreds from an unknown IP in minutes: someone is brute-forcing your SSH. That’s your cue to check whether password auth should even be enabled (key-only SSH kills this entire attack class).
Count attackers per IP in one line:
sudo grep "Failed password" /var/log/auth.log | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort | uniq -c | sort -nr | head
More Log Superpowers
dmesg | tail -30 # kernel messages: hardware errors, driver issueslast # who logged in, when, from where (reads /var/log/wtmp)sudo grep -i "sudo" /var/log/auth.log | tail # who ran what as rootjournalctl --disk-usage # how much space logs are eating
“last” deserves special attention: if you see a login from an IP or at a time you don’t recognize, that’s an incident until proven otherwise.
Defensive Habits
- Centralize logs for anything important — an attacker who owns the box can edit local logs. Forward to a separate log server and local tampering stops mattering.
- Rotate and retain — logs are useless if they filled the disk (service crash) or got deleted after 3 days (investigation needs weeks).
- Actually look at them. Set a weekly 10-minute habit: failed logins, new user accounts, unexpected reboots. Most compromises announce themselves in the logs — to anyone bothering to read.
Your system already did the hard work of recording everything. Reading it is the easy part.



Comments
Post a Comment