SSH allows many authentication tries
- Check
ssh.max_auth_tries- Severity
- low
- Runs
- on the server, in the daily run of the agent
- Looks at
- MaxAuthTries above 6
What the check looks at
MaxAuthTries in the effective sshd configuration (sshd -T). The check warns when it is above 6, the OpenSSH
default.
Risk
MaxAuthTries is the number of attempts sshd allows on one connection; each password a bot tries and each key
a client offers counts. A high value lets a bot guess more passwords per connection before fail2ban, CrowdSec or
the penalties of OpenSSH 9.8 and later react. With key-only login the risk is small, so the severity is low.
How to fix it
Set a lower value in a drop-in file whose name starts with a low number, because sshd keeps the first value it
reads. On RHEL 8, Rocky Linux 8 and AlmaLinux 8, sshd_config does not read /etc/ssh/sshd_config.d/; add the
Include line at the top of it first, as the SSH hardening guide shows.
echo 'MaxAuthTries 3' | sudo tee /etc/ssh/sshd_config.d/10-maxauthtries.conf
sudo sshd -t
Remove the other MaxAuthTries lines:
sudo grep -rn MaxAuthTries /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
Reload sshd.
Debian and Ubuntu
sudo systemctl reload ssh
RHEL, Rocky Linux and AlmaLinux
sudo systemctl reload sshd
Alpine
sudo rc-service sshd reload
A client with many keys in its SSH agent can stop with Too many authentication failures before it reaches
the right key. Name the key in ~/.ssh/config on the workstation:
Host myserver
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
How to check the fix
sudo sshd -T | grep '^maxauthtries'
The output must be maxauthtries 3, or the value you chose (6 at most).
When a warning is fine
Rarely. If a client offers many keys, for example an automation tool that loops over keys, set
IdentitiesOnly and IdentityFile on the client instead of raising the limit.
Sources
- sshd_config(5) (
MaxAuthTries, default 6) - ssh_config(5) (
IdentitiesOnly,IdentityFile)