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: MaxStartups limits unauthenticated SSH connections

Network and access
~/tips/tip-ssh-maxstartups

MaxStartups 5:50:20

Caps unauthenticated SSH connections and shortens the login window to blunt connection floods.

One sshd setting covers connections that have not logged in yet. It matters when a scanner opens a hundred of them at once.

MaxStartups limits the number of concurrent unauthenticated connections to the SSH daemon. Extra connections are dropped until authentication succeeds or the LoginGraceTime of an older one runs out. The default is 10:30:100.

The three numbers are start:rate:full. Once 10 unauthenticated connections exist, new ones are refused with a probability of 30 percent. That probability rises linearly, and at 100 every new connection is refused.

# /etc/ssh/sshd_config.d/20-startups.conf
MaxStartups 5:50:20
LoginGraceTime 30

This starts refusing half of the new connections at 5 open ones and refuses all of them at 20. LoginGraceTime is how long a client gets to log in before the server disconnects it. The default is 120 seconds, and 0 means no limit. Thirty seconds is plenty for a person with a key.

Test and reload as usual:

sudo sshd -t && sudo systemctl reload ssh

You can lock yourself out with this too. If something on the network opens many half-finished connections, your own login is refused along with them, and a deployment script that opens several connections at once can hit a low limit. Keep the numbers modest and keep a session open while you test.

Further reading: sshd_config(5)

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