SSH Permission Denied (publickey): causes and fixes
Originally published at sshdock.com Permission denied (publickey) means you successfully connected to the server over the network, but the server rejected your authentication. You are past the firewall. The SSH daemon is running. The problem is specifically that the server refused to accept your key. This is different from Connection refused (SSH not running or firewall blocking port 22) and…
The "Permission denied (publickey)" error occurs when the SSH server rejects your authentication attempt despite successfully connecting to the server over the network. It is different from connection-related errors like "Connection refused" or "Connection timed out". To diagnose and resolve the issue, the server checks if your public key file exists, contains a matching entry, and if the relevant directories and files have the correct permissions.
Running SSH with verbose output (-vvv) can provide insights into what the server is attempting to authenticate and whether it received your public key. Once you have verified that your public key is present and correctly formatted, check the server's authorized_keys file for proper permissions and ownership. If you are using AWS EC2 instances, ensure that you are using the correct username and key pair that matches the instance's configuration.
Other potential issues include password authentication being disabled or SELinux blocking access to the authorized_keys file. Reviewing server-side logs can offer more detailed information about what caused the authentication failure.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.