Skip to content

Linux auth.log Analysis: Detect SSH Brute-Force Attacks

Linux auth.log Analysis: Detect SSH Brute-Force Attacks

Copy-paste commands for Debian, Ubuntu and RHEL-family servers, run against a sample log and walked through step by step.

Published: | Last reviewed:

To find SSH brute-force attempts in Linux logs, count the Failed password and Invalid user lines in /var/log/auth.log (Debian, Ubuntu) or /var/log/secure (RHEL family), group them by source IP, and then check whether any of those IPs later logged in successfully. A guesser who finally gets in is the case that matters. Everything else is noise you can rank.

If you already suspect one specific server, begin with the Linux compromised server forensics cheat sheet and come back for the SSH side. If you run a jump host, Linux bastion host hardening covers how to build one.

This post only reads logs. Locking SSH down is a separate job, covered in the Linux server hardening baseline, and the incident response guide maps out what to do once you confirm a compromise. Defang any attacker IP with the IOC defanger before you paste it into a ticket or chat.

Key takeaways

  • Where the logs live depends on the distro: /var/log/auth.log on a default Debian or Ubuntu setup, /var/log/secure on RHEL-family systems [1], and the journal wherever journald runs [2].
  • OpenSSH 9.8 and later tag some log lines sshd-session instead of sshd [3], so a search for sshd[ can match nothing.
  • Count failures per source IP, then distinct usernames per IP. Many names with one try each looks like spraying. Many tries on a few names looks like guessing.
  • The line to hunt for is an Accepted entry from an IP that failed first. MITRE lists that sequence as a detection analytic for password guessing [5].
  • OpenSSH 9.8 and later penalises addresses that keep failing authentication by default [3], which can shrink per-IP counts compared with older tutorials.

An SSH brute-force attack is automated, repeated guessing of SSH credentials against a server, usually passwords for common usernames, until one pair works. On the host it leaves a trail of failed authentication messages in the system log, and that trail is what this guide counts. MITRE tracks the technique as T1110.001, Password Guessing [5].

Where does Linux log SSH logins?

On a default Debian or Ubuntu install, rsyslog writes SSH events to /var/log/auth.log. RHEL-family systems write them to /var/log/secure. Both also pass them to the systemd journal, which journalctl reads. If the text file is missing, rsyslog may not be installed, and the journal could be the only copy, so check before you assume anyone deleted logs.

Red Hat documents /var/log/secure as the file for security and authentication messages, and says rsyslog writes those files from the journal feed [1]. That is also why auth.log can be absent on a host that only runs journald.

The SSH authentication messages sit in these places:

SystemText logJournal queryNote
Debian, Ubuntu/var/log/auth.logsudo journalctl -u sshUnit is usually ssh
RHEL, Rocky, AlmaLinux/var/log/securesudo journalctl -u sshdUnit is usually sshd
Not sure whichRun ls /var/logsudo journalctl -u ssh -u sshdMatches whichever unit exists

Reading the system journal needs root, or membership in the systemd-journal, adm or wheel group [2]. You can repeat -u, which is why one command can cover both unit names [2].

Add --since yesterday or --since today to limit the range, and -g to filter by a regular expression [2].

What does a failed SSH login look like in the log?

A failed password attempt shows up as a Failed password line that names the account, the source IP, the source port and the protocol. When the account does not exist on the host, sshd also writes an Invalid user line, and the Failed password line says invalid user. One connection can try several passwords, so count lines instead of connections.

This Failed password line from sshd shows where each fact sits:

Annotated sshd failed password log line A synthetic sshd log line split into five fields: timestamp, host and process, the failed password message, the source IP address, and the source port with protocol. Each field has a short explanation underneath. Nov 15 03:12:44 web01 sshd[2201]: Failed password for invalid user admin from 203.0.113.45 port 51800 ssh2 Server clock time. Check which timezone it uses. Host name, then process name and PID. OpenSSH 9.8 and later can print sshd-session here. Password rejected, and no account named admin exists on this host. Source IP address. This is your main pivot. Client source port and SSH protocol version.
Figure 1. One sshd failure line split into the fields you will use. The line is synthetic, and the IP comes from a documentation range.

Here are a few lines from the sample file I built for this post, so the host name and IPs are made up:

Nov 15 03:12:44 web01 sshd[2201]: Invalid user admin from 203.0.113.45 port 51800
Nov 15 03:12:44 web01 sshd[2201]: Failed password for invalid user admin from 203.0.113.45 port 51800 ssh2
Nov 15 03:12:46 web01 sshd[2202]: Failed password for root from 203.0.113.45 port 51801 ssh2
Nov 15 03:15:30 web01 sshd[2300]: Accepted password for deploy from 203.0.113.45 port 52011 ssh2

sshd logs at INFO by default, and MaxAuthTries defaults to 6 [4]. The same man page says extra failures get logged once a connection reaches half of MaxAuthTries [4]. I did not test how that plays out for each authentication method, so treat line counts as a floor.

Why does grep sshd return nothing on a newer server?

OpenSSH 9.8 split the server into a listener called sshd and a per-session binary called sshd-session. Some log messages now carry the sshd-session name, so a search for sshd followed by a square bracket can miss them. Match sshd with an optional suffix, or match the message text instead of the process name.

The OpenSSH 9.8 release notes list this under potentially incompatible changes and say several log messages changed [3]. The Ubuntu 26.04 sshd_config page names /usr/lib/openssh/sshd-session as the session binary [4].

In my sample, searching for sshd[ matched 92 lines in the classic file and 0 in the new-format file. Matching both names matched 92 in each:

grep -cE 'sshd(-session)?\[' /var/log/auth.log

Check any parser, alert rule or SIEM filter that keys on the sshd process name. My expectation, which I did not test on those tools, is that they need the same fix.

The same release turned on PerSourcePenalties by default [3]. sshd refuses connections from addresses that keep failing, and the default penalty for a failed login starts at 5 seconds, with a 15 second minimum before enforcement and a 10 minute cap [4]. Release notes warn that servers with many users behind NAT may need to adjust it [3]. Expect smaller per-IP counts than older tutorials show. I did not measure by how much.

Which commands count SSH failures by IP and username?

Pull the Failed password lines with grep, keep only the IP address with grep -o, then sort and count with uniq -c. Swap the IP for the username with sed to see which accounts attackers try. These commands match text instead of column positions, so they work on auth.log, secure and journalctl output, whichever timestamp format your system prints.

Command 1 counts failures per source IP. On RHEL-family systems, replace auth.log with secure.

sudo grep "Failed password" /var/log/auth.log | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | sort -rn | head

Sample output:

     30 203.0.113.45
      6 198.51.100.77
      2 192.0.2.10

Command 2 counts failures per username, which shows the accounts attackers try.

sudo grep "Failed password" /var/log/auth.log | sed -E 's/.*Failed password for (invalid user )?([^ ]+) from.*/\2/' | sort | uniq -c | sort -rn | head

Command 3 counts distinct usernames per source IP.

sudo grep "Failed password" /var/log/auth.log | sed -E 's/.*Failed password for (invalid user )?([^ ]+) from ([0-9.]+) .*/\3 \2/' | sort -u | awk '{print $1}' | uniq -c | sort -rn

Sample output:

     10 203.0.113.45
      6 198.51.100.77
      1 192.0.2.10

Command 4 repeats the per-IP count from the journal, for hosts without a text log.

sudo journalctl -u ssh -u sshd --since yesterday --no-pager -g "Failed password" | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | sort -rn | head

In the sample, 203.0.113.45 produced 30 failures across 10 usernames. Command 2 gives you the account view of the same data, which matters when an attacker rotates IPs. The IP pattern covers IPv4 only, so extend it if your server listens on IPv6.

How do you tell a typo from spraying or real guessing?

Compare two numbers for each source IP: how many failures, and how many distinct usernames. A few failures on one real account, then a success, is usually a typo. Many usernames with one or two tries each looks like spraying. Many tries on a short list of names is guessing. Only a later success makes any of them urgent.

The three source IPs in the sample log fall into three different patterns:

Source IPWhat the log showsUsual readingFirst move
192.0.2.102 failures on one real account, then Accepted, within 16 secondsA typoNothing, unless the account owner says it was not them
198.51.100.776 failures on 6 usernames, one try each, spread over about 5 hoursPassword spraying, or a scanner working from a name listCheck whether those accounts exist and allow passwords
203.0.113.4530 failures on 10 usernames within about a minute, then Accepted under 2 minutes laterPassword guessing with a hitTreat as a possible compromise

MITRE files these under Brute Force: password guessing is T1110.001 and password spraying is T1110.003 [5]. The log pattern is how you tell them apart in practice.

Per-IP counts miss attackers who spread attempts over many addresses. Run command 2 as well and look for the same username failing from many IPs.

Triage flow for SSH failures from one source IP A decision flow. First ask whether an Accepted line followed from the same IP. If no, ask whether many usernames were tried once or twice, which points to spraying or a scanner, otherwise guessing on a few names. If yes, ask whether there were only a few failures on one real account, which points to a typo, otherwise a possible compromise. Failures from one source IP Did an Accepted line follow from the same IP? Many usernames, one or two tries each? Only a few failures, all on one real account? If yes: spraying or ascanner. Check whichaccounts allow passwords. If no: guessing on a fewnames. Check penaltiesand exposure. If yes: likely a typo.Confirm with theaccount owner. If no: possiblecompromise. Save logs,then start response. No Yes
Figure 2. A quick triage flow for the failures from one source IP. It sorts cases, and it does not replace reading the log lines.

How do you spot a successful login after many failures?

Walk the log in order and count failures per IP as you go. When an Accepted line appears from an IP that already has failures, print it. This catches the guesser who finally got in. It also catches a colleague who fumbled a password twice, so read the count and the account before you react.

This awk script keeps a running failure count per IP and prints a line when an Accepted entry arrives from an IP that already has failures:

sudo awk '/Failed password/ { if (match($0,/from [0-9.]+/)) f[substr($0,RSTART+5,RLENGTH-5)]++ }
/Accepted/ { if (match($0,/from [0-9.]+/)) { ip=substr($0,RSTART+5,RLENGTH-5); if (f[ip]>0) print f[ip], "failures before success from", ip } }' /var/log/auth.log

Sample output:

30 failures before success from 203.0.113.45
2 failures before success from 192.0.2.10

It reads the file top to bottom, so a success only counts failures that came earlier. Because it matches text, it ran correctly on both timestamp styles in my test.

Two caveats apply. The script has no time window, so run it on one day of log or one journal slice. It also prints the colleague with the typo, as the 192.0.2.10 line shows, so check the count and the account name first.

It matches any Accepted line, which includes Accepted publickey. A key login from an IP that earlier failed password attempts deserves a second look too. MITRE’s detection strategy for password guessing describes this same sequence: repeated failed SSH logins followed by a possible success from the same remote host [5].

What should you do after you find a hit?

Treat a success after many failures as a possible compromise and work in a fixed order: save the logs, confirm with the account owner, end the session if it was not theirs, reset credentials, then look at what the session changed. Preserve evidence first, because every later step alters the system you are examining.

  1. Copy the evidence. Save the relevant log files or a journal export and record a checksum, before rotation or cleanup changes anything.
  2. Ask the account owner whether they logged in at that time.
  3. If they did not, end the session and lock the account while you investigate.
  4. Reset the password. Move the account to key-only login if you can.
  5. Look at what the session did. The forensics cheat sheet linked at the top has the Linux checks.
sudo journalctl -u ssh -u sshd -o short-iso --utc --no-pager > ssh-journal.txt
sha256sum ssh-journal.txt

Turning off password logins removes this whole attack class. PasswordAuthentication defaults to yes in sshd_config [4], so a server that never changed it accepts password guesses. Keep a second session open while you edit SSH settings, so a typo cannot lock you out.

What if the commands return nothing or odd numbers?

Empty output usually has one of a few causes: a process name your pattern misses, a log file that does not exist on this distro, missing permissions, or an older period that rotated out of the file. The table below maps each symptom to a fix, and most fixes take one command to confirm.

SymptomLikely causeFix
Empty output on a newer serverLines tagged sshd-session, and your pattern wants sshd[Use grep -E 'sshd(-session)?\[' or match the message text [3]
No such fileDifferent distro, or rsyslog is not installedTry /var/log/secure on RHEL-family systems [1], or use journalctl [2]
Permission deniedNot root, and not in a journal-reading groupUse sudo, or join systemd-journal, adm or wheel [2]
Counts seem lowRotated files, or fewer failures logged than attempts madeAdd rotated files with zgrep -h on auth.log*, and see the MaxAuthTries note above [4]
IPv6 sources missingThe IP pattern covers IPv4 onlyExtend the regular expression
Times look wrongServer clock uses another timezoneAdd --utc to journalctl [2]

What should you do this week?

Pick one SSH-facing server this week and run commands 1 and 3 on yesterday’s log. Write down the three highest source counts and the distinct usernames next to them. That is your baseline. Run the success check once now, and again after any week where the numbers jump, so you know what normal looks like on this host.

Method and limits. I ran the grep, sed and awk commands against two synthetic 92-line log files: one with classic timestamps and sshd[pid], one with ISO timestamps and sshd-session[pid]. I did not run the journalctl or zgrep commands on a live server, test on RHEL, or check what sshd writes when it refuses a penalised address. Sources were checked on November 15, 2026. Log wording varies by version and settings. The attacks in the sample are invented, not recorded incidents.

Sources & References

  1. Red Hat Enterprise Linux 9: Troubleshooting problems by using log files (Red Hat Documentation)
  2. journalctl(1), Linux manual page (man7.org)
  3. OpenSSH 9.8 release notes (openssh.com)
  4. sshd_config(5), OpenSSH daemon configuration file (Ubuntu Manpages, openssh-server 10.2p1)
  5. Brute Force: Password Guessing, T1110.001 (MITRE ATT&CK)
NK

Cybersecurity Researcher & Technical Editor

UnpanicTech publishes independent cybersecurity research and defensive security analysis. Naseem Khan serves as Technical Editor, with a focus on vulnerability analysis, defensive security, incident response, cloud security, and practical security engineering.

Leave a Comment (Authenticated Users)