Permission denied (publickey) means sshd reached the authentication stage, looked at the keys you offered, and accepted none of them. The connection itself is fine — this is not a firewall or a down service. It is sshd refusing your key, and on cPanel the reasons are a short, well-worn list: the public key is not authorized for that account, the private key on your side does not match, the home or .ssh permissions are too loose for sshd to trust them, or the key was never actually authorized in WHM/cPanel even though you generated it.
What’s happening
SSH key authentication is a match between a private key on your workstation and an authorized public key on the server, stored in ~/.ssh/authorized_keys for that user. When you connect, sshd offers to verify any private key your client presents against the authorized list. If none match — or if sshd refuses to read the authorized file because its permissions are unsafe — you get Permission denied (publickey).
On cPanel specifically, two things trip operators up. First, generating a key in cPanel » SSH Access or WHM » Manage root’s SSH Keys is not the same as authorizing it; an unauthorized key sits in ~/.ssh but is not written to authorized_keys, so sshd ignores it. Second, sshd enforces strict ownership and permission rules: if the home directory is group- or world-writable, or .ssh/authorized_keys have loose modes, sshd silently declines to use the file as a security precaution, and you are bounced even with a perfectly good key. PubkeyAuthentication no or a restrictive AllowUsers/Match block in sshd_config produces the same symptom for a different reason.
How to verify
The verbose client output tells you exactly which keys were offered and how sshd responded:
# Watch the auth negotiation — which key is offered, what is refused
ssh -vvv -i ~/.ssh/id_ed25519 user@server.example.com
# Confirm your local private/public key pair matches each other
ssh-keygen -y -f ~/.ssh/id_ed25519 # derive pubkey from private
cat ~/.ssh/id_ed25519.pub # compare the two strings
On the server (via console or an existing session), check that the key is actually authorized and that permissions are sane. sshd is strict here:
# Is the public key present in the account's authorized list?
cat /home/<cpaneluser>/.ssh/authorized_keys
# sshd refuses loose perms — these are the values it expects
ls -ld /home/<cpaneluser> # home should NOT be group/world writable
ls -ld /home/<cpaneluser>/.ssh # expect drwx------ (700)
ls -l /home/<cpaneluser>/.ssh/authorized_keys # expect -rw------- (600)
Then confirm sshd itself permits key auth and allows this user:
# Server-side policy
grep -Ei 'pubkeyauthentication|authorizedkeysfile|allowusers|^match' /etc/ssh/sshd_config
# The authoritative reason for the refusal is in the server log
tail -50 /var/log/secure | grep sshd
Authentication refused: bad ownership or modes in /var/log/secure is the unmistakable permissions signature. no matching key found means the public key is simply not in authorized_keys. User user not allowed because not listed in AllowUsers is a policy block.
The fix
- Authorize the key, do not just generate it — in cPanel » SSH Access » Manage SSH Keys, find the public key and click Authorize (or WHM » Security Center » Manage root’s SSH Keys for root). Generating a key without this step leaves it unused. To do it by hand, append the
.pubcontents to/home/<cpaneluser>/.ssh/authorized_keys. - Fix home and
.sshpermissions — sshd will ignore a perfectly valid key if the path is too open. Set them precisely:chmod 711 /home/<cpaneluser>(or stricter),chmod 700 /home/<cpaneluser>/.ssh,chmod 600 /home/<cpaneluser>/.ssh/authorized_keys. Thebad ownership or modeslog line clears the moment these are right. - Fix ownership — the
.sshdirectory and its files must be owned by the account user, not root. Reset withchown -R <cpaneluser>:<cpaneluser> /home/<cpaneluser>/.ssh. A misownedauthorized_keys(common after a manualcpas root) is refused exactly like loose modes. - Point at the right private key — if your client offers the wrong key first, sshd may exhaust attempts before reaching the good one. Be explicit with
-i ~/.ssh/id_ed25519, or pin it in~/.ssh/configwithIdentityFileandIdentitiesOnly yesso only the intended key is sent. - Confirm the pair actually matches —
ssh-keygen -y -f <private>must output the exact string sitting inauthorized_keys. If they differ, you authorized a public key whose private half you no longer have; generate a fresh pair and authorize the new public key. - Enable key auth in sshd — if
PubkeyAuthenticationisno, no key will ever work. Set it toyesin/etc/ssh/sshd_config, runsshd -tto validate, thensystemctl restart sshd. CheckAuthorizedKeysFilestill points at.ssh/authorized_keysif it was customized. - Clear an AllowUsers / Match block — if
sshd_configrestricts logins withAllowUsersor aMatchstanza that excludes this account, the key is correct but the user is barred. Add the user to the allow list (or adjust the match), validate, and restart sshd. - Use a passphrase agent if the key is encrypted — a passphrase-protected key that your agent has not loaded can present as a silent failure. Run
ssh-add ~/.ssh/id_ed25519and retry;ssh-add -lconfirms the key is held by the agent.
Once key auth works, this is the moment to turn off password logins (PasswordAuthentication no) so the account can only be reached with the authorized key — far harder to brute-force. Stack Harbor manages SSH key access and hardening under cPanel server administration — start a conversation when key auth will not cooperate.