The SSH daemon (sshd) is refusing new connections because a specific IP address or user account has exceeded the allowed number of failed authentication attempts. This is a security measure to prevent brute-force attacks, but it can lock out legitimate users if misconfigured or if a user genuinely forgets their password.
Here are the common culprits and how to fix them:
1. Client-Side Brute-Force Attempt (Most Common)
-
Diagnosis: Check the
sshdlogs on the server for repeated connection attempts from a single IP address, often with varying usernames or incorrect passwords.sudo grep "Failed password" /var/log/auth.log | tail -n 50or on RHEL/CentOS:
sudo grep "Failed password" /var/log/secure | tail -n 50Look for a consistent IP address showing up many times.
-
Fix: Identify and block the offending IP address on the server using
iptablesorfirewalld. Foriptables:sudo iptables -A INPUT -s <offending_ip_address> -j DROP sudo service iptables save # Or equivalent for your distroFor
firewalld:sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<offending_ip_address>" reject' sudo firewall-cmd --reloadThis works by instructing the server’s firewall to silently discard all incoming packets from that specific IP, preventing any further communication.
2. Incorrect SSH Key Permissions on the Server
-
Diagnosis: If you’re using SSH keys, incorrect permissions on the
~/.sshdirectory or~/.ssh/authorized_keysfile on the server can causesshdto reject authentication, even with the correct key. Check permissions on the server:ls -ld ~ ~/.ssh ~/.ssh/authorized_keysThe
~/.sshdirectory should be700(drwx------) and~/.ssh/authorized_keysshould be600(-rw-------). The user’s home directory (~) should not be group-writable. -
Fix: Correct the permissions on the server.
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown -R <username>:<username> ~/.ssh # Ensure correct ownershipThis fixes the issue by ensuring that only the owner of the SSH key can read, write, or execute the necessary files, which is a security requirement for
sshd.
3. Client-Side SSH Configuration Issues
-
Diagnosis: The client machine might be trying to connect using an incorrect username or an expired SSH key repeatedly. Check your local SSH client configuration (
~/.ssh/config) and the SSH agent (ssh-add -l). On your local machine:cat ~/.ssh/config ssh-add -lLook for any misconfigured
HostName,User, orIdentityFiledirectives. -
Fix: Correct your
~/.ssh/configfile or ensure the correct key is loaded into your SSH agent. Example~/.ssh/configfix:Host my-server HostName 192.168.1.100 User correct_username IdentityFile ~/.ssh/my_correct_keyIf using
ssh-agent, ensure the correct key is added:ssh-add ~/.ssh/my_correct_keyThis resolves the problem by making sure the client is presenting the correct credentials (username, hostname, and key) to the server for each connection attempt.
4. PAM Configuration on the Server
-
Diagnosis: The Pluggable Authentication Modules (PAM) system on the server might be configured with a very low limit for authentication attempts. Check the relevant PAM configuration file, often
/etc/pam.d/sshd.sudo cat /etc/pam.d/sshdLook for lines related to
pam_tally2.soorfaillock.so. For example, you might seeauth required pam_tally2.so onerr=succeed deny=5 unlock_time=900. -
Fix: Adjust the
denyandunlock_timeparameters in/etc/pam.d/sshd. If usingpam_tally2.so, changedeny=5to a higher number (e.g.,deny=10) andunlock_time=900(15 minutes) tounlock_time=0(never auto-unlock, manual reset required) or a longer duration.# Example change: auth required pam_tally2.so onerr=succeed deny=10 unlock_time=3600This increases the threshold for failed attempts before lockout and/or changes how long a user/IP is locked out, preventing accidental lockouts from minor typos.
If using
faillock.so(more modern):sudo pam-auth-update # To check current PAM configurationEdit
/etc/security/faillock.confor/etc/pam.d/sshdto adjustdenyandunlock_time. Example/etc/security/faillock.conf:# Increase deny count and unlock time deny = 10 unlock_time = 3600This achieves the same goal by configuring the
faillockmodule to allow more failed attempts before imposing a lockout.
5. Incorrect Username or Password on the Server
-
Diagnosis: The user account on the server simply has the wrong password set, or the user is trying to log in with a username that doesn’t exist. Log in directly on the server console or via another method to check user accounts and passwords.
sudo passwd <username>(This will prompt you to set a new password if you are root or have sudo privileges).
-
Fix: Reset the password for the user account on the server.
sudo passwd <username>Enter a new, correct password. This directly resolves the issue by providing valid credentials for authentication.
6. SSH Server Configuration (MaxAuthTries)
-
Diagnosis: The
sshd_configfile on the server might have a very lowMaxAuthTriessetting.sudo grep MaxAuthTries /etc/ssh/sshd_configIf this line exists and is set to a low number (e.g.,
MaxAuthTries 3), it’s a likely cause. -
Fix: Increase the
MaxAuthTriesvalue in/etc/ssh/sshd_config.# Example: Increase to 6 MaxAuthTries 6After editing, restart the
sshdservice:sudo systemctl restart sshdThis tells the SSH daemon to allow more individual authentication attempts (e.g., password or key checks) per connection before it considers the session failed and logs the "Too Many Authentication Failures" error.
7. IP Address Blocked by fail2ban or Similar Tools
-
Diagnosis: If you have
fail2banor a similar intrusion-prevention system installed, it might have automatically banned the IP address after detecting too many failed attempts. Checkfail2banstatus and logs:sudo fail2ban-client status sshd sudo grep <offending_ip_address> /var/log/fail2ban.log -
Fix: Unban the IP address using
fail2ban-client.sudo fail2ban-client set sshd unbanip <offending_ip_address>This tells
fail2banto remove the IP address from its ban list, allowing connections to resume.
After resolving these issues, the next error you’re likely to encounter is a "Permission denied (publickey,password)." message if your SSH keys are still not correctly set up or if you’ve forgotten the actual password.