Tools and labs
Linux Logs for Beginners: Find Failed Logins, Sudo Use and Suspicious Activity
Logs are where attacks leave footprints. If you can read Linux logs quickly, you can answer the most important question in any investigation: what happened, and when? Here is a practical start on your own lab machine.
Where Linux keeps logs
Most logs live in /var/log. Common files:
/var/log/auth.log(Debian, Ubuntu) or/var/log/secure(RHEL, Fedora, CentOS style): logins, SSH, sudo and authentication./var/log/syslogor/var/log/messages: general system messages.- Web server logs, such as
/var/log/apache2/access.logor/var/log/nginx/access.log.
Many modern distributions use systemd, which stores logs in a binary journal read with journalctl. Some systems keep both the journal and text files. Reading logs usually needs sudo.
Find failed SSH logins
On your lab VM with SSH enabled, try logging in with a wrong password a few times from another lab VM. Then:
sudo grep "Failed password" /var/log/auth.log
sudo grep "Failed password" /var/log/auth.log | wc -l
To see which IP addresses failed most:
sudo grep "Failed password" /var/log/auth.log | grep -oE "from [0-9.]+" | sort | uniq -c | sort -nr
This one line is a mini brute force detector. Many real servers on the internet see constant automated SSH guessing, which is why key based login and tools like fail2ban are common.
Successful logins and sudo use
sudo grep "Accepted" /var/log/auth.log # successful SSH logins
sudo grep "sudo:" /var/log/auth.log # commands run with sudo
last # recent logins
lastb # failed logins (needs sudo)
A successful login right after many failures from the same IP is a classic alert worth investigating. So is sudo use by an account that normally never uses it.
Using journalctl
sudo journalctl -u ssh # logs for the SSH service (may be sshd)
sudo journalctl --since "1 hour ago"
sudo journalctl -p err # errors and above
sudo journalctl -f # follow live, like tail -f
sudo journalctl -b # since last boot
Combine filters, for example sudo journalctl -u ssh --since today. The journal is great for quick, time bound questions.
Build a simple timeline
In an investigation, you want a clear story. For your lab exercise:
- Note the time you started an nmap scan from your attacker VM. See our nmap guide.
- Note when you tried wrong SSH passwords, then a correct one.
- Run a sudo command.
- Now read the logs and write a timeline: time, event, source IP, user.
Compare your timeline with what you actually did. This is exactly what SOC and incident response people do daily, see our SOC analyst day in life post.
Protecting and keeping logs
- Logs on the same machine can be deleted by an attacker with root access. Organisations forward logs to a central server or SIEM.
- Keep clocks accurate with NTP, so timelines across systems match.
- Keep logs long enough. In India, CERT-In's April 2022 directions require covered entities to maintain logs of their ICT systems for 180 days, and CERT-In's October 2026 advisory on AI agent attacks also recommends retaining logs for at least 180 days.
- Configure log rotation so disks do not fill up.
Practice plan
Week one: read auth.log daily on your lab VM. Week two: write a small Bash or Python script that summarises failed and successful logins by IP and user. Week three: install a free log tool in your lab and forward logs to it. Document everything in your portfolio. Logs might feel boring at first, but they are where real security work happens.
Frequently asked questions
My system has no auth.log. Why? Some distributions use only the systemd journal by default, or use a different file name like secure. Try journalctl instead.
Can I read logs without sudo? Usually not for security logs, because they contain sensitive information. Some users in an admin group may have read access.
What is a SIEM? A Security Information and Event Management system collects logs from many systems, correlates them and raises alerts. SOC analysts spend much of their time in a SIEM.
How do I practise without a server on the internet? Use your home lab. Generate events yourself with failed logins, sudo use and scans, then find them in the logs.
Educational content, not legal advice. Check official sources before you rely on it. If you have lost money, call 1930 now. Terms