brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: PerSourcePenalties is the fail2ban that newer sshd already has built in

Network and access
~/tips/tip-sshd-persourcepenalties

PerSourcePenalties authfail:30s max:30m

Know how OpenSSH 9.8 and later block noisy addresses by themselves, and how to tune it.

Since OpenSSH 9.8, sshd keeps score of addresses that misbehave and refuses them for a while. It is on by default, so if you run a recent server you already have it.

The man page lists what counts. A client that fails to authenticate gets 5 seconds, in recent releases a login with a user that does not exist also 5, and one that crashes sshd 90 seconds. Penalties add up, to at most 10 minutes by default, and they only kick in after 15 seconds have been collected. You can change the numbers:

PerSourcePenalties authfail:30s max:30m

The penalty applies to the whole network block set by PerSourceNetBlockSize, not one address.

What I would add is an exemption for your own network and monitoring, so a script with a wrong key does not lock out the whole office:

PerSourcePenaltyExemptList 192.0.2.0/24,203.0.113.10

Check the current values with sudo sshd -T | grep -i persource.

Is fail2ban still useful? It can still do things this cannot, like longer bans, firewall level blocking and other services. But for plain SSH noise, this already takes the edge off, and the noauth penalty for scanners is set low on purpose. The man page warns that raising it hits legitimate tools like ssh-keyscan too.

Further reading: sshd_config man page, OpenSSH 9.8 release notes

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link