How-to

Fix "Permission denied (publickey)"

This message means the server offered only key login and none of your keys matched. Verbose output on the client and the auth log on the server always reveal which part failed.

What does the error actually mean?

The server only accepts the publickey method for this user, your client tried every key it had, and the server rejected all of them. Nothing is broken in the network: the TCP connection worked and the handshake finished. The problem sits in one of four places: the key your client offers, the user name you log in as, the authorized_keys file on the server, or a policy setting that refuses that key type.

How do I see which key the client offered?

Run the client with one verbose flag and filter the interesting lines:

ssh -v -o IdentitiesOnly=yes -i ~/.ssh/ops_ed25519 kofi@198.51.100.40 2>&1 | grep -Ei 'offering|authentications|denied|accepted'

Look for Offering public key followed by the file name. If your intended key is not listed, the client never sent it: the path is wrong, the file is unreadable, or the agent holds different keys. With IdentitiesOnly=yes only the named file is tried; agent keys stay out of the attempt, and the unrelated "Too many authentication failures" error cannot get in the way.

Am I logging in as the right user?

Keys are tied to accounts. A key placed for root at install time does not work for kofi, and a key added to kofi does not work for root. On a fresh machine from us, keys you selected in the panel go to root. Compare the server copy with your local public key by fingerprint:

ssh-keygen -lf ~/.ssh/ops_ed25519.pub                 # on your computer
ssh-keygen -lf /home/kofi/.ssh/authorized_keys      # on the server, one line per key

The SHA256 values must match exactly.

Are the file permissions too loose?

This is the most common cause on servers. With StrictModes yes, the default, sshd ignores an authorized_keys file if the file, the .ssh folder or the home directory can be written by anyone other than the owner. Fix ownership and modes in one go:

chown -R kofi: /home/kofi/.ssh
chmod go-w /home/kofi
chmod u=rwx,go= /home/kofi/.ssh
chmod u=rw,go= /home/kofi/.ssh/authorized_keys

A home directory with mode 775, often created by a script or a shared group setup, is enough to make sshd quietly refuse the key. The server log says so plainly, which is why reading it saves time.

Is SELinux blocking the file?

On Rocky Linux, AlmaLinux and CentOS Stream, files copied with tools that keep their original labels can carry the wrong SELinux context, so sshd is not allowed to read them. Restore the expected labels:

restorecon -Rv /home/kofi/.ssh
ls -Z /home/kofi/.ssh/authorized_keys

The label should read ssh_home_t. If home directories live somewhere unusual, such as /srv/home, add a file context rule with semanage fcontext before running restorecon.

Is my key type still accepted?

Old RSA keys work, but the old way of signing with them does not. OpenSSH 8.8 and later turn off the ssh-rsa signature algorithm, which uses SHA-1. Current clients sign RSA keys with SHA-2 automatically, so the failure usually appears with an old client against a new server or with tooling built on outdated libraries. DSA keys are gone completely in OpenSSH 10.0, which Debian 13 ships. The lasting fix is a new ed25519 key: ssh-keygen -t ed25519 -f ~/.ssh/ops_ed25519.

What does the server log say?

SystemWhere to look
Ubuntu, Debianjournalctl -u ssh --since -10min or /var/log/auth.log
Rocky, AlmaLinux, CentOS Streamjournalctl -u sshd --since -10min or /var/log/secure
FreeBSD 14/var/log/auth.log

Typical lines are Authentication refused: bad ownership or modes, which points to permissions, or userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms, which points to the signature algorithm. Run sshd -T | grep -Ei 'authorizedkeysfile|pubkeyauth' to confirm the server looks for keys where you placed them.

What if I am locked out completely?

If a root session is still open anywhere, fix the files from there. If not, and password login is also disabled, the machine needs a reinstall from the panel, which wipes the disks and creates a new root password. Add your public key in the panel's SSH keys page before reinstalling so it lands on the fresh system.

Keep Reading

Log in with an SSH key

Create an ed25519 key, install it on your machine through the panel or ssh-copy-id, and log in without typing the root password.

Open

Set up passwordless SSH

Go from a root password to key-only access in one careful pass: user, key, agent, then switch off every password method on the server.

Open

SSH keys

How SSH key pairs replace passwords, how to make an ed25519 key and how to have it placed on your machine at install time.

Open

AlmaLinux

AlmaLinux 9 for hosting panels and software written for the Red Hat family, with no subscription to buy.

Open

FAQ

Quick Answers

Most often the permissions on the home directory, .ssh or authorized_keys are too open, so sshd ignores the file. The server log names the exact reason.

The .ssh folder should be 700 and authorized_keys 600, both owned by the user, with a home directory not writable by group or others.

RSA keys work when signed with SHA-2, which current clients do automatically. DSA keys no longer work in OpenSSH 10.0.

Pass -i with the key path and -o IdentitiesOnly=yes, or set both in a Host block of your SSH config.

Keys added in the panel go to root. Copy the public key into the new user's authorized_keys file yourself.