Who logged in to the machine: login logs
Where to view successful and failed logins, how to read last, lastb, and journalctl, how to track actions via sudo, and how to configure log retention.
Updated August 23, 2026
Every login to a machine leaves a trace. Being able to read those traces in five minutes is what separates a calm incident review from guesswork.
Quick overview
last -a -n 20
lastb -a -n 20
lastlog
who
w
last shows successful logins with addresses, lastb — failed attempts, lastlog — when each user last logged in. who and w show who is on the machine right now.
If lastlog shows a login date for a system user like www-data, that's a serious reason to investigate.
systemd journal
journalctl -u ssh -n 100
journalctl -u ssh --since "2026-08-20" --until "2026-08-21"
journalctl _COMM=sshd | grep "Accepted"
journalctl _COMM=sshd | grep "Failed password" | tail -50
Key lines:
| Line | Meaning |
|---|---|
Accepted publickey for artem | Successful login by key |
Accepted password for root | Successful login by password — a cause for concern |
Failed password for invalid user admin | Brute-forcing non-existent names, background noise |
Disconnected from authenticating user | Attempt aborted |
On Debian and Ubuntu, the same events are duplicated in /var/log/auth.log; on AlmaLinux, in /var/log/secure.
grep "Accepted" /var/log/auth.log
grep -c "Failed password" /var/log/auth.log
Hundreds of failed attempts per day on a public address are normal. What's abnormal is something else: a successful login from an address you don't recognize. fail2ban helps against the noise.
What was done after login
journalctl -t sudo -n 100
grep sudo /var/log/auth.log
cat /home/artem/.bash_history
Command history is unreliable: it's easy to clear, and it isn't recorded during non-interactive sessions. The sudo log is far more honest — it's maintained by the system, not the shell. Another argument in favor of the "regular user plus sudo" scheme described in the article users and sudo.
Full kernel-level auditing:
apt install -y auditd
auditctl -w /etc/passwd -p wa -k passwd_changes
ausearch -k passwd_changes
Storage
By default, the systemd journal may live in memory and be lost on reboot. That's bad for incident review. The file /etc/systemd/journald.conf:
[Journal]
Storage=persistent
SystemMaxUse=500M
MaxRetentionSec=1month
systemctl restart systemd-journald
journalctl --disk-usage
A size limit is mandatory: a journal that has eaten the disk stops services.
Common mistakes
| Mistake | Consequence | Solution |
|---|---|---|
| Journal isn't saved between reboots | Traces are lost | Storage=persistent |
Relying only on .bash_history | Data is easy to forge | Check the sudo and auditd logs |
| Didn't limit the journal size | Disk filled up | SystemMaxUse |
| Treating brute-force noise as a hack | False alarm | Look at Accepted, not Failed |
If you find a successful login from someone else's address, the logs on the machine itself can no longer be considered reliable: whoever logged in could have edited them. Follow the article signs of compromise and assume the machine will have to be reinstalled.