Skip to main content
“Permission denied (publickey)” means SSH is running and reachable, but the server only accepts key logins and didn’t accept your key. Usually you used the wrong username, your SSH client offered a different key, the public key isn’t in ~/.ssh/authorized_keys, or that folder has the wrong permissions. Run ssh -v to see which key is offered, then fix the server side from the VNC console.

Before you start

  • The text in brackets lists the login methods the server still offers. (publickey) alone means password logins are switched off, so typing a password can’t work.
  • For fixes on the server, use the VNC console on a VPS. If you also forgot the password, reset the root password first. On a dedicated server, open a ticket for KVM/IPMI access.
  • Commands use sudo. As root, leave it out.

Step 1: See what your client sends

Look for these lines:
  • No Offering public key line: your client has no key to offer. Point to it with -i (Cause 2).
  • A key is offered but no Server accepts key follows: the server doesn’t know that key, or ignores it (Causes 2 to 4).

Cause 1: Wrong username

The key is installed for one user only. Logging in as root when the key belongs to alex, or the reverse, fails. Fix: use the user the key was set up for:
If root is refused but other users work, check PermitRootLogin in /etc/ssh/sshd_config and the files in /etc/ssh/sshd_config.d/. The value no blocks root completely. See disable root login.

Cause 2: Your client offers the wrong key

SSH tries your default keys (such as ~/.ssh/id_ed25519). A key saved elsewhere, or with another name, isn’t used automatically. Fix: name the key:
Save it in your SSH config file with IdentityFile so you don’t have to type it. In PuTTY, select the .ppk file under Connection > SSH > Auth > Credentials. PuTTY can’t use an OpenSSH key directly: convert it with PuTTYgen first.

Cause 3: The public key isn’t in authorized_keys

Check on the console (replace alex with your user):
Compare it with the public key on your computer (cat ~/.ssh/id_ed25519.pub). The whole line must match, on one line. Fix: add the public key, one key per line:
For root, the file is /root/.ssh/authorized_keys. To manage keys through the panel instead, see manage SSH keys.

Cause 4: Wrong ownership or permissions

OpenSSH ignores authorized_keys if other users could change it. The SSH log shows:
Check the log:
Fix: give the folder and file to the user and remove write access for others:
On AlmaLinux and Rocky, also restore the SELinux labels, which can be wrong on files copied in from elsewhere:

Cause 5: You wanted to log in with a password

If you don’t have a key at all, the server needs password logins. Don’t switch them on permanently on a public server. Instead, log in on the console, create a key pair on your computer and add the public key as in Cause 3.

How to check it worked

Frequently asked questions

Can I just copy my private key to the server?

No. Only the public key (the .pub file) goes on the server. The private key stays on your computer.

It worked yesterday. What changed?

Common causes are a rebuild (which replaces authorized_keys), a new computer without your old key, or a chmod -R 777 on the home folder. Check the log in Cause 4 first.

Why does ssh-copy-id fail with the same error?

ssh-copy-id needs a working login to copy the key, usually a password. With password logins off, add the key through the console instead.

VPS and dedicated server guides

Every guide in this section.

Create and use SSH keys

Make a key pair and install it.

Use PuTTY

Keys and settings in PuTTY.

SSH connection refused

When SSH doesn’t answer on the port.

Host key verification failed

The other common SSH warning.

Checked against the official OpenSSH sshd manual (AUTHORIZED_KEYS FILE FORMAT) and Ubuntu’s OpenSSH server guide on 4 November 2026; the error, the ssh -v output, the wrong-key case and the “bad ownership or modes” log line were reproduced and fixed on Ubuntu 24.04 LTS (OpenSSH 9.6). The SELinux step was not tested.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026