Fix SSH Too Many Authentication Failures on Linux VPS

Resolve 'Too many authentication failures' when connecting to a Linux VPS via SSH. Fix ssh-agent key exhaustion with IdentitiesOnly, ssh_config, and MaxAuthTries.

Fix SSH Too Many Authentication Failures on Linux VPS
Linux VPS SSH Diagnostic Runbook

To fix SSH too many authentication failures: Bypass automatic ssh-agent key cycling by connecting with ssh -o IdentitiesOnly=yes -i ~/.ssh/your_key user@host.[1][4] For a permanent fix, add IdentitiesOnly yes and a specific IdentityFile inside ~/.ssh/config, or flush excess keys from memory using ssh-add -D.[1][3]

Follow this engineering runbook to diagnose ssh-agent key exhaustion, isolate verbose OpenSSH handshake failures, and lock per-host authentication policies across Linux VPS and bare-metal servers.[1][2]

Why SSH Triggers Too Many Authentication Failures on a Linux VPS

When OpenSSH prints Received disconnect from <IP> port 22:2: Too many authentication failures, the server dropped the TCP session before your valid key or password prompt was even reached.[2] Under the SSH Authentication Protocol (RFC 4252), each rejected "publickey" or keyboard attempt triggers an SSH_MSG_USERAUTH_FAILURE response that counts against the server’s per-connection failure budget.[6]

By default, the OpenSSH daemon (sshd) sets MaxAuthTries to 6.[2] If your local ssh-agent holds seven or more private keys—for example, separate keys for GitHub, GitLab, staging boxes, and production clusters—the ssh client offers agent keys sequentially until six rejections occur, causing an immediate disconnect before key seven or password fallback is attempted.[1][2]

Common Triggers Behind SSH Key Exhaustion

  1. Unscoped ssh-agent Accumulation: Every key loaded via ssh-add or macOS Keychain / GNOME Keyring is offered automatically to every host you connect to unless explicitly restricted.[1][3]
  2. Tighter Hardened Server Limits: Production Linux hosts hardened for compliance often lower MaxAuthTries from 6 to 3 or 4, leaving almost zero margin when an agent offers multiple keys.[2]
  3. Default Identity Probing Order: Even without ssh-agent, OpenSSH checks default IdentityFile candidates (~/.ssh/id_rsa, id_ecdsa, id_ecdsa_sk, id_ed25519, id_ed25519_sk) alongside any GSSAPI or PKCS11Provider tokens before prompting for a password.[1]

Diagnostic Matrix: SSH Authentication Failure Causes and Fixes

Failure Symptom Diagnostic Output (ssh -vvv) Root Cause Direct Remediation
Disconnect before password prompt Multiple Offering public key lines followed by Too many authentication failures ssh-agent holds more keys than server MaxAuthTries Connect with -o IdentitiesOnly=yes -i ~/.ssh/<key>[1]
Fails even with -i flag specified Client still offers agent keys before the -i key -i adds a key without suppressing ssh-agent defaults Pair -i with IdentitiesOnly yes in CLI or ~/.ssh/config[1]
Fails on hardened VPS with 3+ keys Disconnect after 2 or 3 SSH_MSG_USERAUTH_FAILURE packets Server sshd_config enforces MaxAuthTries 3 Pin a single IdentityFile per Host block locally[2]
Password-only VPS still disconnects Client offers agent keys before PreferredAuthentications reaches password No SSH key installed on server, but client burns attempts with agent keys Run ssh -o PubkeyAuthentication=no user@host for one-off password login[1]
Hardware key / YubiKey blocks login SecurityKeyProvider or PKCS11Provider exhausts slots first Smartcard or FIDO2 token keys offered ahead of VPS key Scope IdentitiesOnly yes and remove unused agent keys via ssh-add -d[1][3]

Step 1: Confirm Which Keys Your Client Is Sending

Before editing configuration files, inspect the exact key negotiation sequence with OpenSSH verbose mode.[4] Open your local terminal and run ssh with -v (or up to -vvv for maximum verbosity) alongside ssh-add -l to list every identity currently loaded in your agent:[3][4]

# List all key fingerprints currently cached in ssh-agent
ssh-add -l

# Trace exact public keys offered during the SSH handshake
ssh -v -p 22 root@192.0.2.50 2>&1 | grep -E "Offering|Next authentication|Too many"

If ssh-add -l prints six or more keys—or if ssh -v shows several Offering public key: lines before printing Received disconnect ... Too many authentication failures—you have confirmed client-side key exhaustion.[2][3]


How to Fix SSH Too Many Authentication Failures (Client & Server Methods)

When managing fleets of Nextgen Hosting Dedicated Servers or low-latency Pakistan Dedicated Servers, isolating SSH keys per host keeps administrative access deterministic and prevents accidental account lockouts.[1]

Method 1: Immediate One-Line CLI Override (IdentitiesOnly=yes)

Passing -i alone does not prevent ssh from first trying keys cached in ssh-agent.[1] Combine -o IdentitiesOnly=yes with -i so the client sends only the exact key file you specify:[1][4]

# Connect using ONLY the specified private key
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_prod root@192.0.2.50

If you are connecting to a newly provisioned VPS that only accepts password authentication and have no SSH key installed yet, disable public-key probing for that session:[1]

# Bypass public key attempts and jump straight to password authentication
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password root@192.0.2.50

Method 2: Permanent Per-Host Pinning in ~/.ssh/config

For daily server administration, define a dedicated Host entry in ~/.ssh/config (and lock permissions to 600).[1] Setting IdentitiesOnly yes inside a Host stanza restricts authentication strictly to the IdentityFile declared for that server:[1]

Host nextgen-prod-01
    HostName 192.0.2.50
    User ubuntu
    Port 22
    IdentityFile ~/.ssh/id_ed25519_prod
    IdentitiesOnly yes

Apply strict ownership permissions to your local configuration file and test the alias:

chmod 600 ~/.ssh/config
ssh nextgen-prod-01

Pro Tip: Enable IdentitiesOnly Globally with Host *
If you manage dozens of cloud instances and Git repositories, place IdentitiesOnly yes under a trailing Host * block at the bottom of ~/.ssh/config. Every explicit Host block above it will still use its assigned IdentityFile without ever leaking unrelated ssh-agent keys.[1]

Method 3: Flush or Prune ssh-agent Memory

If a stale IDE extension or automated deployment script loaded excess keys into your active agent, purge them directly from memory using ssh-add:[3]

# Remove one specific key from ssh-agent
ssh-add -d ~/.ssh/old_project_key

# Or delete all identities from ssh-agent and reload only the active key
ssh-add -D
ssh-add ~/.ssh/id_ed25519_prod

Running ssh-add -D clears all cached keys from the agent without deleting any files from ~/.ssh/ on disk.[3]

Method 4: Server-Side MaxAuthTries Adjustment (Use Sparingly)

If a legacy CI/CD runner cannot pass IdentitiesOnly=yes and you control the remote VPS via console or KVM, you can inspect or adjust MaxAuthTries in /etc/ssh/sshd_config.[2][5] Note that sshd begins logging authentication failures once attempts reach half of MaxAuthTries.[2]

# Edit the OpenSSH daemon configuration on the VPS
sudo nano /etc/ssh/sshd_config

# Set a measured limit (default is 6; avoid setting excessively high values)
MaxAuthTries 6

# Validate syntax before restarting the daemon
sudo sshd -t

After sshd -t returns zero errors, reload the service:[5]

# Ubuntu / Debian
sudo systemctl reload ssh

# RHEL / AlmaLinux / Rocky Linux
sudo systemctl reload sshd

Common Pitfall: Raising MaxAuthTries Instead of Fixing Client Config
Increasing MaxAuthTries to 20 or higher widens the per-connection window for automated brute-force scanners and masks broken client hygiene. Always keep MaxAuthTries at 3 to 6 on internet-facing servers and enforce IdentitiesOnly yes on client workstations.[1][2]


Step-by-Step Terminal Checklist: Resolving SSH Auth Exhaustion

Execute this ordered checklist whenever an SSH client disconnects with Too many authentication failures:

  1. Audit active agent keys: Run ssh-add -l to count how many private keys ssh-agent currently holds in memory.[3]
  2. Trace the handshake: Run ssh -v user@host and count Offering public key entries prior to disconnect.[4]
  3. Verify immediate access: Connect once with ssh -o IdentitiesOnly=yes -i ~/.ssh/<target_key> user@host (or -o PubkeyAuthentication=no if using password login).[1][4]
  4. Pin the host configuration: Add Host, IdentityFile, and IdentitiesOnly yes entries to ~/.ssh/config and run chmod 600 ~/.ssh/config.[1]
  5. Purge unused agent identities: Execute ssh-add -D and re-add only actively required keys with ssh-add ~/.ssh/<target_key>.[3]
  6. Audit server baseline: Confirm /etc/ssh/sshd_config keeps MaxAuthTries between 3 and 6, validate with sudo sshd -t, and reload ssh if modified.[2][5]

Frequently Asked Questions: Fix SSH Too Many Authentication Failures

Why does SSH say too many authentication failures?

SSH prints Too many authentication failures when the client exceeds the server’s MaxAuthTries limit (which defaults to 6 in OpenSSH) during a single connection.[2] This usually happens because ssh-agent automatically offers every cached private key in sequence until six rejections occur, disconnecting before the correct key or password prompt is tried.[1]

How do I fix SSH too many authentication failures without changing server settings?

Connect with ssh -o IdentitiesOnly=yes -i ~/.ssh/your_key user@host to restrict authentication to a single private key.[1][4] To make the fix permanent without touching the remote VPS, configure IdentityFile and IdentitiesOnly yes under a Host block in ~/.ssh/config.[1]

What does IdentitiesOnly yes do in SSH config?

According to the OpenSSH ssh_config manual, setting IdentitiesOnly yes forces ssh to use only the authentication identity and certificate files explicitly configured in ssh_config or passed via -i on the command line.[1] It prevents the client from offering extra keys stored in ssh-agent, PKCS11Provider, or SecurityKeyProvider.[1]

How do I clear cached SSH keys from ssh-agent?

Run ssh-add -l to inspect all keys currently loaded in ssh-agent, then run ssh-add -d /path/to/key to remove a specific identity or ssh-add -D to delete all identities from the agent in memory.[3] Deleting keys from ssh-agent only clears the session cache and preserves your key files on disk.[3]

Should I increase MaxAuthTries in sshd_config on my VPS?

In most production environments, you should leave MaxAuthTries at its default of 6 or lower it to 3 or 4 rather than increasing it.[2] Raising MaxAuthTries allows external scanners more authentication guesses per TCP connection, whereas setting IdentitiesOnly yes on the client resolves the issue safely.[1][2]


Run Production Linux Workloads Without Access Bottlenecks

Eliminate noisy neighbors, packet loss, and sluggish SSH sessions. Deploy enterprise NVMe compute, isolated network uplinks, and dedicated root access with Nextgen Hosting.

Explore Global Dedicated Servers Explore Pakistan Dedicated Servers

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.

Sources & Official References
  1. OpenBSD Project. "ssh_config(5) — OpenSSH client configuration file (IdentitiesOnly, IdentityFile, PreferredAuthentications)." OpenBSD Manual Pages. Available at: https://man.openbsd.org/ssh_config
  2. OpenBSD Project. "sshd_config(5) — OpenSSH daemon configuration file (MaxAuthTries)." OpenBSD Manual Pages. Available at: https://man.openbsd.org/sshd_config
  3. OpenBSD Project. "ssh-add(1) — adds private key identities to the OpenSSH authentication agent (-l, -d, -D)." OpenBSD Manual Pages. Available at: https://man.openbsd.org/ssh-add
  4. OpenBSD Project. "ssh(1) — OpenSSH remote login client (-i, -o, -v)." OpenBSD Manual Pages. Available at: https://man.openbsd.org/ssh
  5. Canonical Ltd. "OpenSSH server — Ubuntu Server documentation." Ubuntu Server Guide. Available at: https://ubuntu.com/server/docs/how-to/security/openssh-server/
  6. Ylonen, T. and C. Lonvick. "RFC 4252: The Secure Shell (SSH) Authentication Protocol." Internet Engineering Task Force (IETF). Available at: https://www.rfc-editor.org/rfc/rfc4252

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.