An SSH server can answer a connection and still refuse to open a session for the requested account. Fixing Permission denied (publickey) starts with finding out which key OpenSSH offered for that login.
A private key saved under a custom filename can be left out of a login attempt even when the matching public key is already registered. Selecting the private key explicitly can restore access without changing the server.
An existing session or console gives you a way to inspect the target account when the server refuses the intended key. A server administrator can make the same checks using the public key fingerprint while the private key stays on your client.
Steps to fix SSH Permission denied (publickey):
- Trace the failed SSH login from the original client.
$ ssh -vvv -S none deploy@server.example.com ##### snipped ##### debug1: Authenticating to server.example.com:22 as 'deploy' ##### snipped ##### debug1: Offering public key: /home/alex/.ssh/id_ed25519 ED25519 SHA256:VzPojdPagzrJpiScZsT9swi+Qrvxg/Hs4TlCGh+FdaQ ##### snipped ##### deploy@server.example.com: Permission denied (publickey).
Both client commands use the original username and destination, including any host alias and connection options such as -p 2222. -vvv shows the offered keys, and -S none forces a fresh connection.
- Compare the intended public key’s fingerprint with the Offering public key lines in the trace.
$ ssh-keygen -lf ~/.ssh/work_ed25519.pub 256 SHA256:wcNXE0TQ9URYsY6IYQTVD5o4/APNwxX7IADpvfXYZRo work (ED25519)
The command takes the intended key’s .pub file. If its SHA256 fingerprint is absent from the offers, skip to the last step to select that key explicitly. If it appears in an offer but has no matching Server accepts key line, check the registered keys on the server.
- Check the remote account’s registered keys if the server refused the intended key.
The server checks assume the default ~/.ssh/authorized_keys file and run in the target account’s shell, for example after sudo -iu deploy for deploy. From a separate admin shell, substitute the target account’s actual home for ~. For a custom AuthorizedKeysFile or AuthorizedKeysCommand, see the linked server configuration guide.
$ ssh-keygen -lf ~/.ssh/authorized_keys 256 SHA256:wcNXE0TQ9URYsY6IYQTVD5o4/APNwxX7IADpvfXYZRo work (ED25519)
If the fingerprint is missing, the account owner or administrator can add the verified public key alongside existing entries.
- Inspect the server’s key file permissions if the fingerprint matches but the server refuses the key.
$ ls -ld ~ ~/.ssh ~/.ssh/authorized_keys drwxr-x--- 4 deploy deploy 4096 Nov 21 09:34 /home/deploy drwx------ 2 deploy deploy 4096 Nov 21 09:34 /home/deploy/.ssh -rw-----w- 1 deploy deploy 86 Nov 21 09:34 /home/deploy/.ssh/authorized_keys
With StrictModes enabled, OpenSSH can reject keys because of unsafe ownership or modes on the file or its directories. The w in the last triplet marks the displayed authorized_keys file as world-writable.
- Retry the same SSH login with the intended private key.
The -i option takes your private-key path in place of the example path.
$ ssh -vvv -S none -o IdentitiesOnly=yes \ -o PreferredAuthentications=publickey \ -i ~/.ssh/work_ed25519 deploy@server.example.com id -un ##### snipped ##### debug1: Offering public key: /home/alex/.ssh/work_ed25519 ED25519 SHA256:wcNXE0TQ9URYsY6IYQTVD5o4/APNwxX7IADpvfXYZRo explicit ##### snipped ##### debug1: Server accepts key: /home/alex/.ssh/work_ed25519 ED25519 SHA256:wcNXE0TQ9URYsY6IYQTVD5o4/APNwxX7IADpvfXYZRo explicit ##### snipped ##### Authenticated to server.example.com ([192.0.2.10]:22) using "publickey". ##### snipped ##### deploy
If the intended key is offered but refused, follow the server checks and linked repair, then rerun this login check. If Server accepts key is followed by a signing failure, the problem is on the client, so check the local key path and passphrase or check the key in your agent before retrying this login.
IdentitiesOnly=yes excludes extra agent keys and PreferredAuthentications=publickey prevents password fallback. A key passphrase unlocks the key locally. The client trace confirms the intended key only if it is the last key named by Offering public key, Server accepts key, or Trying private key before Authenticated … using “publickey”, with no signing failed line after that key and before authentication. The output from id -un confirms the remote account.
If you can read the server’s SSH log, its Accepted publickey for entry confirms which key logged in by naming the account and the key’s SHA256 fingerprint.
Accepted publickey for deploy from 192.0.2.20 port 35020 ssh2: ED25519 SHA256:wcNXE0TQ9URYsY6IYQTVD5o4/APNwxX7IADpvfXYZRo