An internet-facing OpenSSH 10.5 server logs tens of thousands of failed logins a day; what do PerSourcePenalties, MaxStartups and MaxAuthTries each limit, and when is a log-scraping ban tool still worth adding?
answer
- sshd now punishes the source
- penalties accrue, then refuse
- per connection versus per address
- random early drop
- logs move, filters break
basics
~20 sSince 9.8, PerSourcePenalties makes sshd refuse an address that keeps failing, for an accrued period up to 10 minutes by default; MaxStartups randomly drops excess unauthenticated connections; MaxAuthTries caps attempts per connection. A ban tool adds longer, firewall-level, multi-service bans.
solid answer
~40 sEach limit bounds something different. `MaxAuthTries` (default 6) caps authentication attempts on one connection, so a guesser just reconnects. `LoginGraceTime` (120 s) and `MaxStartups` (default `10:30:100`) bound unauthenticated connections: from 10 pending, sshd refuses new ones with 30% probability, rising linearly to all of them at 100. `PerSourcePenalties`, on by default since OpenSSH 9.8, follows an address across connections: failed authentication (5 s), an invalid user name (5 s, added in 10.3), never authenticating (1 s), exceeding the grace time (10 s) or crashing sshd (90 s) accrue a penalty, and once it passes the 15-second minimum the source is refused, for at most 10 minutes. A log-scraping ban tool still earns its place for bans of hours, drops at the firewall and other services, as long as its filters follow sshd's log changes.
go deeper
Recall that sshd 9.8 and later penalise addresses that keep failing, that MaxAuthTries is per connection, and that switching passwords off is the real fix.
Explain each limit's scope: attempts per connection, unauthenticated connections server-wide with random early drop, and penalties that follow a source address across connections.
Tune for real traffic: exempt NAT'd office and management ranges, raise authfail or invaliduser for hostile sources, watch INFO-level enforcement logs, and keep ban-tool filters in step with process names.
Decide where rate limiting lives, inside sshd, at the host firewall or at the edge, weighing collateral damage to shared addresses, visibility for operators, and whether port 22 needs to face the internet at all.
## Four limits, four different scopes A server on port 22 is scanned constantly. sshd has several built-in limits, and the classic interview mistake is to treat them as interchangeable. Each one bounds a different quantity: | Directive | What it bounds | Default in 10.5 | |---|---|---| | `MaxAuthTries` | authentication attempts within **one connection**; failures are logged once half the value is reached | 6 | | `LoginGraceTime` | how long one connection may stay unauthenticated | 120 seconds | | `MaxStartups` | concurrent **unauthenticated connections, server-wide**, with random early drop | `10:30:100` | | `PerSourceMaxStartups` | concurrent unauthenticated connections from **one source** | `none` | | `PerSourcePenalties` | refusal of a **source address** after bad outcomes, across connections | on | `MaxStartups 10:30:100` reads as start:rate:full. When 10 unauthenticated connections are pending, sshd refuses a new one with probability 30%; the probability rises linearly until, at 100 pending, every new attempt is refused. Connections that have authenticated do not count. ## How PerSourcePenalties works Introduced in OpenSSH 9.8 and **enabled by default**, it is the only built-in limit that remembers a client between connections. 1. The listener process watches each connection's pre-authentication outcome; parent processes also notice a child that crashes. 2. Each bad outcome records a penalty against the client's source address: - `authfail` 5s: disconnected after failed authentication attempts; - `invaliduser` 5s: tried a user name that is not a real account (added in 10.3); - `noauth` 1s: disconnected without trying to authenticate; - `grace-exceeded` 10s: did not finish within `LoginGraceTime`; - `crash` 90s: made sshd crash, a sign of someone probing for bugs. 3. Penalties accumulate. Nothing is enforced until the total passes `min` (15s); repeated offences push it up to `max` (10m). 4. While a penalty is enforced, **all new connections** from that address are refused, along with any others in the same `PerSourceNetBlockSize` range (default `32:128`, so each address on its own). Connections already in progress are not affected. 5. The tracking table holds up to 65536 IPv4 and 65536 IPv6 ranges by default; on overflow the default `permissive` mode drops existing penalties early rather than refusing everyone. Since 10.1 sshd logs enforcement at INFO, so blocks are visible under default logging; earlier they were logged at VERBOSE. ```ini # Defaults made explicit, a harsher stance on bad names, and a trusted range MaxAuthTries 6 LoginGraceTime 2m MaxStartups 10:30:100 PerSourcePenalties authfail:30s invaliduser:60s max:30m PerSourcePenaltyExemptList 198.51.100.0/24 ``` ## Tuning for real users - **Shared addresses.** Everyone behind one NAT or proxy address shares a penalty. The 9.8 release notes warn operators of servers with such clients to review these settings; exempt known office and management ranges with `PerSourcePenaltyExemptList`. - **Scanners you run yourself.** sshd_config(5) cautions that the `noauth` penalty may catch legitimate scanning tools such as `ssh-keyscan`. - **`MaxAuthTries` too low** hurts honest clients that offer several keys before the right one; it is not a defence against a botnet anyway, because each bot just opens a new connection. ## Reading the numbers Consider one bot address that opens a connection, fails, disconnects and repeats. Each such connection accrues the 5-second `authfail` penalty. Nothing is enforced until the accrued total passes the 15-second `min`, so by about the third failed connection the address starts being refused outright; if it keeps returning, the penalty keeps growing towards the 10-minute `max`. A legitimate user who mistypes once accrues 5 seconds and is not refused for that single slip. A crashing client jumps straight past the minimum with 90 seconds. That asymmetry is the design: cheap for honest mistakes, expensive for persistent failure. ## Where a log-scraping ban tool still fits A tool such as fail2ban reads sshd's log lines and inserts firewall rules. Compared with the built-in penalties: - it can ban for hours or days, and drop packets before they reach sshd at all; - it covers other services on the host with the same mechanism, and can share ban lists; - it reacts only after a log line is written, and depends on the **exact log text**: since 9.8 many messages are tagged `sshd-session` instead of `sshd`, and since 10.0 authentication messages may come from `sshd-auth`, so filters written for older releases can silently stop matching. ## What none of this does None of these limits makes a guessable password safe; they slow and thin the traffic. The decisive control is switching password-capable methods off, after which the failures in the log are noise. How much a distributed guessing campaign actually costs an attacker is a question for the material on credential attacks.
- Why does lowering MaxAuthTries to 2 do little against a botnet guessing passwords?`MaxAuthTries` counts attempts within one connection, so a guesser just opens another. What follows an address across connections is `PerSourcePenalties`, and against thousands of addresses even that only thins the traffic, which is why password authentication itself should be off. A very low value also hurts clients that offer several keys first.
- Staff behind the office NAT are suddenly refused after a few typos. What happened, and what do you change?They share one public address, so failures from different people accrued penalties against the same source, and once past the 15-second minimum the whole address was refused. Add the office range to `PerSourcePenaltyExemptList`. The 9.8 release notes flag servers with clients behind NAT or proxies for exactly this review.
- After upgrading to OpenSSH 10.0, a log-scraping ban tool stopped banning anyone. What is a likely cause?Its filters match log lines by process tag and message text. Since 9.8 many messages are tagged `sshd-session` instead of `sshd`, and since 10.0 authentication messages may come from `sshd-auth`. A filter keyed to the old tag sees nothing, so it must be updated for the new process names.
PerSourcePenalties is a doorman who remembers faces: anyone who keeps fumbling the password is turned away from the door for a while, longer each time, while the accounts inside stay untouched. Everyone arriving on the same bus is turned away together unless they are on the guest list.
- MaxAuthTries limits how many times one address may try in total.
- PerSourcePenalties must be switched on before sshd blocks anything.
- MaxStartups counts every connection, including logged-in sessions.
- PerSourcePenalties locks the user account that was being guessed.
- A ban tool's sshd filter keeps working unchanged across OpenSSH upgrades.
Assumes OpenSSH 10.5: PerSourcePenalties arrived on by default in 9.8, the invaliduser penalty in 10.3, and INFO-level logging of enforcement in 10.1.