You configure your server, generate a new SSH key pair, and add the public key to the authorized_keys file. After saving, you attempt to connect, only to be greeted with the frustrating error: "server refused public-key signature despite accepting key." This specific message indicates a mismatch between the authentication offer sent by the client and the validation rules applied by the server. Unlike a simple permission error, this problem suggests the server acknowledged the key file but rejected the cryptographic proof presented during the handshake. Diagnosing this issue requires a systematic approach to examining permissions, key formats, and server directives.
Understanding the SSH Key Exchange Process
To resolve why a server refused public-key signature despite accepting key, it is essential to understand the underlying handshake. When a client initiates a connection, it offers one or more public key algorithms and signs a piece of data using the corresponding private key. The server, which already holds the public key in the authorized_keys file, verifies this signature. If the verification succeeds, access is granted; if it fails, the server proceeds to the next offered method. The error in question occurs when the server validates the public key format but determines the signature itself to be invalid or unsupported for that specific key.
Common Causes of Signature Rejection
Several technical oversights can lead to a server refusing a valid key. A frequent culprit is a mismatch in the key encoding or algorithm; the server might be configured to accept only specific types, such as RSA or ED25519, while the client is attempting to use another. Another possibility is that the private key file on the client machine has been corrupted or altered, breaking the cryptographic link. Furthermore, the presence of extra characters, such as line breaks or spaces in the authorized_keys file, can cause the server to parse the key incorrectly, leading to a failed signature check even though the key appears to be loaded.
Investigating File Permissions and Ownership
Secure Shell relies heavily on file permissions to maintain security, and improper settings are a primary reason for authentication failures. While the error message specifically mentions the signature, incorrect ownership can indirectly cause the server to treat the key as untrusted. The home directory, the .ssh folder, and the authorized_keys file itself must have strict permissions. Typically, the home directory should be writable only by the owner, the .ssh directory should be accessible exclusively by the user, and the authorized_keys file must not be group-writable or world-writable.
Verifying Key Integrity and Format
When the server accepted the key, it confirmed the file structure was syntactically correct, but the signature verification requires the raw binary data to match perfectly. You should verify the private key is intact by inspecting its header. For RSA keys, the file should begin with "-----BEGIN RSA PRIVATE KEY-----" or "-----BEGIN OPENSSH PRIVATE KEY-----". If you are using the newer OpenSSH format, the private key is generally robust, but converting an old PEM key without the proper headers can lead to silent failures. Moreover, ensuring the key was generated without a passphrase—or that the agent is correctly handling the passphrase—is vital, as a mismatched expectation here will halt the signing process entirely.