SSH Authentication Failed? Fix Guide 2026

You typed ssh [email protected], hit enter, and got Permission denied (publickey) for the fourth time tonight. Sound familiar? If you’re staring down an SSH authentication failed error at 2 AM, take a breath — this SSH authentication failed fix guide covers the actual causes, not the copy-paste nonsense you’ll find on random forums.

Here’s the thing: SSH auth failures are almost never random. Something specific is misconfigured, and the server is telling you exactly what if you know where to look.

Let’s find it.

First, Read the Error Line Properly

That trailing parenthesis in Permission denied (publickey) is the whole story. It tells you which methods the server actually offered.

  • (publickey) — the server wants a key, and yours didn’t match
  • (publickey,password) — keys failed, but password auth is still open
  • Permission denied (password) — key auth is disabled server-side, or your key was rejected outright
  • Connection closed by remote host — this isn’t auth at all; it’s usually fail2ban, TCP wrappers, or a full disk

Nine out of ten times I’ve debugged this for someone, the fix was in that parenthetical. People just skip past it.

The Permission Bug That Gets Everyone Once

SSH is paranoid about file permissions, and honestly? It has good reason. If your private key is readable by anyone else on the machine, ssh-agent refuses to use it.

Run this and check the output:

ls -la ~/.ssh/

You want 700 on ~/.ssh and 600 on id_rsa or id_ed25519. Fix them like this:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/authorized_keys

On the server side, the home directory matters too. A chmod 777 /home/deploy someone set “temporarily” two years ago will silently break key auth forever. Use chmod 755 /home/deploy and chown -R deploy:deploy /home/deploy/.ssh.

Quick sanity check: if your key works as one user but fails as another, permissions and ownership are almost always the culprit — not the key itself.

sshd_config: The Lines That Block You

The server config lives at /etc/ssh/sshd_config. Open it and look for these:

  1. PubkeyAuthentication yes — must be enabled for key login
  2. PasswordAuthentication no — if this is off and your key is broken, you’re locked out
  3. PermitRootLogin prohibit-password — root with a password won’t work, period
  4. AllowUsers or AllowGroups — if your username isn’t listed, you get denied even with perfect credentials

After editing, always validate before restarting: sshd -t. If it prints nothing, you’re good. Then systemctl reload sshd (or ssh on Debian/Ubuntu).

Restarting a broken sshd over a remote connection is how people end up locked out of production. Reload, don’t restart. And keep a second session open. Learn more about 7 Ways to Fix a VPN.

The authorized_keys trap

Someone pastes a public key with a line break in the middle, or with ssh-rsa turned into ssh-rsa with a trailing space. The file looks fine. It isn’t.

Verify with ssh-keygen -l -f ~/.ssh/authorized_keys. If it returns a fingerprint, the key parsed correctly. If it errors, rebuild the line.

Client-Side: Is Your Key Even Being Offered?

This is where verbose mode earns its keep:

ssh -vvv user@server

Scan the output for Offering public key: followed by a fingerprint. If you don’t see your key listed at all, the client never tried it. Common causes: the key isn’t in ~/.ssh/, your ~/.ssh/config points to the wrong IdentityFile, or the agent is holding a stale key.

Clear that with ssh-add -D, then re-add the right one: ssh-add ~/.ssh/id_ed25519.

Also check for a mismatched host entry. A Host block in your config that accidentally matches the server with the wrong User or IdentityFile will waste an hour of your life. Run ssh -G user@server | grep identityfile to see what SSH actually resolves.

When the Server Itself Is Blocking You

Sometimes auth never happens because something upstream killed the handshake. If you see the connection drop instantly, look here before touching keys:

  • fail2ban — check fail2ban-client status sshd; too many retries and your IP is banned for an hour
  • Account expiry — chage -l user shows if the password or account expired
  • MaxStartups / MaxAuthTries — left at defaults, but aggressive reverse proxies and load balancers can trip them
  • Disk full — sshd can’t write to /var/run, so it drops the session. df -h catches this fast

In my experience, a full /var partition masquerades as an auth bug more often than anyone expects. Especially on small VPS instances running a mail server and a log-heavy docker stack. If you’re on a cheap box, check disk before anything else — it’ll save you twenty minutes.

Tunnels, VPNs, and Android Clients

Different beast, same symptoms. If you’re connecting through a tunnel, the failure usually isn’t SSH at all — it’s the tunnel refusing to route port 22. For more on this, see 5 Proven SSH Connection Refused Fixes. Another option worth trying is 5 Quick SSH Connection Refused Fixes.

For Android, that means checking whether v2rayNG, NekoBox, or HTTP Injector is actually allowing SSH traffic through the payload. Many free configs only whitelist 80 and 443 via SNI host headers. Try running sshd on 443 and connecting with ssh -p 443 user@host. If that works, it was never an auth problem.

On WireGuard, confirm the AllowedIPs covers your SSH target’s subnet. A 0.0.0.0/0 config with a DNS leak blocking the route is a classic.

Host key verification failed

Different message, related frustration. You rebuilt the server and the fingerprint changed:

ssh-keygen -R 203.0.113.10

Then reconnect. Just be certain the change is legitimate — this warning exists to stop man-in-the-middle attacks. On a shared network, treat it as a red flag, not an annoyance.

Your Five-Minute Checklist

1. Read the parenthetical in the error. 2. Check chmod 700/600 on both ends. 3. Run ssh -vvv and confirm your key is offered. 4. Clear the agent and re-add. 5. Validate sshd -t before reloading. 6. Check fail2ban and disk space.

Work down that list in order and you’ll solve the vast majority of cases without ever touching a config file twice.

Where I’d Start Tomorrow

If you just want it to work — no wrestling with sshd_config at midnight — spin up a clean SSH environment and compare against your broken setup side by side. That’s the fastest way to spot the difference.

You can grab a free account at claudessh.com and test your keys against a working config. Ten minutes there usually beats three hours of guessing.

RouterSSH WireGuard VPN offers the same protocol with free accounts ready in under a minute.