Every SSH login leaves a trace. The question is whether anyone ever looks at it. When you audit SSH logins on your VPS, you find out who connected, when, from where, and whether anyone tried and failed. Most VPS owners never check until something breaks or a bill spikes. By then the evidence is gone or buried under weeks of noise.
Two tools ship with almost every Ubuntu and Debian server and cover most of what you need: lastlog for a quick overview, and journalctl for the full story. This guide walks through both, shows you what normal looks like, and gives you a routine you can run in five minutes a week.
How to Audit SSH Logins with Lastlog
Lastlog answers one simple question: when did each user last log in? The lastlog command reads the file /var/log/lastlog and prints one line per account, with the username, the port or terminal, the source IP address, and the time of the last login. Run it with no arguments:
lastlog
The output looks like this:
Username Port From Latest root pts/0 203.0.113.42 Mon Nov 24 09:12:04 +0000 2026 deploy pts/1 198.51.100.17 Sun Nov 23 18:40:31 +0000 2026 www-data **Never logged in**
Scan the list for anything you do not recognise. A user account that should never log in over SSH, a login at 3 a.m. from an IP you have never seen, or a service account like www-data showing a login at all are all worth a second look. To check one account only, pass its name:
lastlog -u deploy
Lastlog has one hard limit: it only stores the most recent login per user. It cannot tell you about the five logins before that one, and it records nothing about failed attempts. That is why it works best as a first pass. If you want the full picture, including the signs of a suspicious login that a single last-login line can hide, journalctl is the next step.
Dig Into the Full Log with Journalctl
Journalctl reads the systemd journal, which holds your ssh login history going back as far as your journal retention allows. On Ubuntu and Debian the service is called ssh; on RHEL-based systems it is sshd. Start with the most recent entries:
journalctl -u ssh --since "yesterday"
Two log lines matter most. A successful login looks like this:
Nov 24 09:12:04 vps sshd[1842]: Accepted publickey for root from 203.0.113.42 port 51234 ssh2
A failed one looks like this:
Nov 24 09:14:41 vps sshd[1901]: Failed password for root from 45.148.10.9 port 40218 ssh2
To see only the failures, filter with grep:
journalctl -u ssh --since "today" | grep "Failed password"
And to see only successful logins:
journalctl -u ssh --since "7 days ago" | grep "Accepted"
The --since flag takes plain English like "yesterday", "7 days ago", or an exact timestamp like "2026-11-20 00:00:00". Add -f to watch new entries live, which is handy while you test a login from another machine. If you run journalctl -u ssh and get nothing back, check the service name first with systemctl status sshd or systemctl status ssh. On a server that has been running for months, the journal may also be trimmed by size limits, so old entries can be gone even if the server never rebooted.
Lastlog vs Journalctl: Which One to Use When
Neither tool replaces the other. They answer different questions, and most audits use both:
| Question | Tool | Command |
|---|---|---|
| When did each user last log in? | lastlog | lastlog |
| Did anyone log in today? | journalctl | journalctl -u ssh --since "today" | grep Accepted |
| Is someone guessing passwords? | journalctl | journalctl -u ssh | grep "Failed password" |
| Which IPs connected this week? | journalctl | journalctl -u ssh --since "7 days ago" | grep Accepted |
| Has a dormant account been used? | lastlog | lastlog -u <username> |
On older systems without systemd, the same SSH lines live in /var/log/auth.log (Debian and Ubuntu) or /var/log/secure (RHEL). The format of the lines is the same, so the reading skills in this guide transfer directly.
How to Read a Failed Login Attempt
A single failed login means almost nothing. You mistype a password, a script retries with an old key, a colleague uses the wrong username. The pattern is what matters. A run of failed password attempts from one address is the classic brute-force signature, but context decides whether it is an attack or just noise. Open a day of failed attempts and look for these shapes:
- Many attempts, one username: someone is hammering a single account, usually
rootoradmin. A handful of tries from your own IP is a typo. Hundreds from one foreign IP is a brute-force attempt. - Many attempts, many usernames: a scanner working through a dictionary of common names like
test,oracle,postgres, andubuntu. This is background noise on any public server, but the volume tells you whether your firewall and fail2ban rules are actually biting. - Attempts outside your working hours: logins at 2 a.m. your time from an IP in a country you have no connection to deserve a closer look, especially if they succeed.
- Accepted logins you cannot explain: this is the one that matters most. If journalctl shows an accepted login from an IP you do not recognise, treat the server as possibly compromised until you prove otherwise.
To count failures per IP for a quick triage, pipe the output through a small sort:
journalctl -u ssh --since "7 days ago" | grep "Failed password" | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head -20
The IPs at the top of that list are your repeat offenders. A few dozen failures a week from scattered addresses is normal for a public VPS. Thousands from a single address in one day is not.
Turn One-Off Checks Into a Weekly Routine
An audit you run once is a snapshot. An audit you run every week is a baseline, and baselines are what let you spot change. The routine takes about five minutes:
- Run
lastlogand confirm every account’s last login looks familiar. - Run the accepted-logins grep for the past seven days and check every IP.
- Run the failed-password count and note the top offenders.
- If anything is new or unexplained, dig into that IP’s full entries before doing anything else.
If you want the check to run itself, wrap those commands in a small shell script and schedule it with cron or a systemd timer to email you the output once a week. Keep the output short. A report nobody reads is the same as no report.
One practical warning: journal logs grow, and on a server under constant brute-force fire they grow fast. If your disk fills up, the journal is one of the first places to look. Setting up log rotation before logs fill the disk keeps your history available without letting it eat the whole filesystem. You can also cap the journal size with SystemMaxUse in /etc/systemd/journald.conf, but remember that a smaller cap means a shorter look-back window for your next audit.
What to Do When Something Looks Wrong
Finding a strange login is the start of the work, not the end of it. The right response depends on what you found.
If you see failed attempts only, and no accepted login from an unknown IP, your defences held. Still, use the scare as a prompt. Switch the accounts that matter to SSH keys instead of passwords, and disable password authentication entirely once every legitimate user has a key. Password guessing stops working the moment there is no password to guess.
If you see an accepted login you cannot explain, act the same day. Change the affected account’s password and keys, check ~/.ssh/authorized_keys for keys you did not add, and look at running processes and recent file changes for anything unfamiliar. Then tighten the server properly: key-only login and fail2ban close the two most common ways attackers get back in, and a firewall rule that only allows SSH from your own IP removes the noise altogether.
Finally, write down what normal looks like for your server: your IPs, your usual hours, your usual accounts. The next time you audit SSH logins, that note is what turns a wall of log lines into a yes-or-no answer in under a minute.