Home
How to Fix the SSH Permission Denied (Publickey) Error on Linux and Windows
The "Permission denied (publickey)" error is one of the most frequent hurdles encountered by developers, system administrators, and DevOps engineers when attempting to access remote servers or Git repositories via Secure Shell (SSH). It signals that the SSH client attempted to authenticate using a public key, but the server rejected all offered identities or found no valid credentials to verify.
To resolve this issue effectively, one must understand that SSH is designed with a "security-first" philosophy. If any part of the authentication chain—from the local file permissions to the server-side configuration—is slightly misaligned, the connection will be severed to prevent unauthorized access.
Understanding Why SSH Rejects Your Public Key
SSH public key authentication relies on an asymmetric cryptographic exchange. Your local machine holds a private key, and the remote server holds a corresponding public key in a specific file (typically ~/.ssh/authorized_keys). During the handshake, the server sends a challenge that only the holder of the private key can solve.
When you see the "Permission denied (publickey)" message, it usually means:
- The server does not have your public key in its "allowed" list.
- The file permissions on either the client or the server are too permissive, causing the SSH daemon to ignore them for security.
- The local SSH client is not offering the correct private key to the server.
- The SSH agent is not running or has not loaded the required identity.
- The server's SSH configuration explicitly denies public key authentication or uses incompatible algorithms.
Step 0: Diagnostic Mode with Verbose Output
Before applying random fixes, it is essential to identify where exactly the breakdown occurs. The SSH client provides a verbose mode that reveals the internal negotiation process.
Run your connection command with the -v (verbose) flag:
-
Topic: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Or, when testing the SSH connection: ssh -T git@github.com git@github.com: Permission denied (publickey). Or while starting the SSH agent: Start-Service: Cannot start service ssh-agent on computer '.' Error: 1058 ===================================https://assets-global.website-files.com/67539d69b985be57f5091d7d/6871168594a47e93de0dae4d_19147528581.pdf
-
Topic: SSH Permission Denied (publickey): Causes and Fixes | Linuxizehttps://linuxize.com/post/fix-ssh-permission-denied-publickey/
-
Topic: How to Fix \"SSH Failed Permission Denied (publickey, gssapi-keyex, gssapi-with-mic)\"?https://www.tutorialspoint.com/article/how-to-fix-quot-ssh-failed-permission-denied-publickey-gssapi-keyex-gssapi-with-mic-quot