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)