When your server breaks, the answer is in the logs. In this hands-on Level 2 finale you'll learn where Ubuntu keeps its logs (/var/log and the systemd journal), how to filter them like a pro with journalctl, tail -f, grep and zgrep, how to find out exactly who is attacking your SSH with one pipeline, and a 5-step troubleshooting method. Then we solve 3 real cases step by step: nginx won't start (port already in use), a full disk caused by a 12 GB log (and how to prevent it with logrotate and a journal size limit), and a mysterious reboot at night (out of memory).
โฑ Chapters
0:00 Down, full, rebooted: why?
0:19 Where logs live (/var/log)
0:57 journalctl essentials
1:25 Text logs: tail -f, grep, zgrep, less
2:01 Pro move: who is attacking my SSH?
2:33 The 5-step troubleshooting method
2:57 Case 1: nginx won't start (port in use)
3:27 Case 2: disk full (12 GB log)
4:01 Prevent it: logrotate + journal limit
4:31 Case 3: why did it reboot? (out of memory)
5:04 Common mistakes
5:25 Cheat sheet
5:48 Like & subscribe
6:00 Level 2 complete, homework & up next
๐ The troubleshooting method
1. What exactly is broken? Get the exact error.
2. Check the status: systemctl status app, df -h, free -h
3. Read the logs: journalctl -u app -n 50, journalctl -p err -b
4. Change ONE thing, then test again.
5. Verify, and watch the logs: journalctl -f
โจ๏ธ Commands from this video
ls /var/log where the text logs live
journalctl -u ssh -n 3 last 3 lines of one service
journalctl -p err -b only errors since this boot
journalctl -b -1 -p err errors from the PREVIOUS boot (before a crash)
journalctl -u cron --since "1 hour ago" a time window
journalctl -u nginx -f follow live (Ctrl+C stops)
journalctl --list-boots when did the server boot / stop?
sudo tail -f /var/log/syslog follow a text log live
grep -i error /var/log/syslog | tail -3 find lines, ignore case
grep -c 'Failed password' /var/log/auth.log count matching lines
zgrep -i error /var/log/syslog.2.gz search inside compressed old logs
less +G /var/log/syslog open at the end (/ search, q quit)
grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head -3 top 3 attacking IPs
sudo ufw deny from 203.0.113.45 block an IP
sudo ss -tlnp which program uses which port
sudo du -sh /var/log/* | sort -h | tail -3 the biggest log folders
sudo truncate -s 0 /var/log/myapp/app.log empty a log safely (even if it's open)
sudo journalctl --vacuum-size=500M shrink the journal
sudo logrotate -d /etc/logrotate.d/myapp test a logrotate rule (dry run)
SystemMaxUse=500M in /etc/systemd/journald.conf: cap the journal
๐ /etc/logrotate.d/myapp
/var/log/myapp/*.log {
daily
rotate 7
compress
missingok
copytruncate
}
โ ๏ธ Deleting a log file that a program still has open does NOT free the space: use truncate -s 0.
๐บ Full course playlist:
โ Previous โ #14 Bash Scripting Basics:
โถ Next โ #16 Level 3: Firewall: coming soon
๐ฌ Homework: find the top 3 IPs attacking your SSH, and add a logrotate rule for health.log from episode 14. Post your top attacker count in the comments!
๐ Level 2 complete! Next: Level 3.
๐ If this helped, like & subscribe, it keeps the course free.
ยฉ netacademy.ge
#Linux #UbuntuServer #SysAdmin