Troubleshooting SSH Permission Denied (publickey)

Learn how to troubleshoot and fix the SSH Permission Denied (publickey) error. Understand the causes and solutions for this common SSH authentication issue.

Updated: 17 Dec, 23 by Susith Nonis 4 Min

List of content you will read in this article:

A tool that many admins couldn't imagine getting by without. It's like a trusty wrench in the toolkit that helps keep the server wheels turning. But like any tool, it can sometimes refuse to cooperate, and you may need to do some troubleshooting to fix it. If you've ever encountered the Permission Denied (publickey) error, then you know how frustrating it can be. It's one of those pesky SSH errors that can ruin your day. But fear not, for we're here to help you understand what causes it, and more importantly, how you can fix it. So, grab a cup of coffee, and let's dive into some SSH problem-solving.

Oh boy, the SSH Permission Denied (publickey) Error. It's like the curse of the SSH (Secure Shell) universe. It's the error message that makes you want to shake your fist at the computer and scream, "Why me?!" But fear not, my friends. I'm here to shed some light on this mysterious error.

In a nutshell, the SSH Permission Denied (publickey) Error occurs when your SSH connection gets rejected by a remote server because it doesn't recognize your public key. Learn How to Troubleshoot SSH Connection Refused Errors

It's like trying to get into a high-security facility without having the right access card. You'll just be sitting outside, twiddling your thumbs and feeling rejected. So, if you get hit with this error, it means that you need to give the server permission to access your key.

ssh permission denied (publickey)

Check SSH Agent to find Permission Denied  public key issue

If you are using an SSH agent to manage your keys, ensure that your key is loaded into the agent. You can check the agent using the following command:

$ ssh-add -l

If the agent is not running, you can start it using the command:

$ eval "$(ssh-agent -s)"

Learn more about SSH Keys: Discover their significance and setup process.

Check the SSH Public Key Permissions

Before checking the key permissions, ensure that you have copied the public key to the remote server. If you have already done this, make sure that the permissions on the key files are correct. The private key file should have 600 permissions, and the public key file should have 644 permissions. To change the file permissions, execute the following commands:

$ chmod 600 ~/.ssh/id_rsa

$ chmod 644 ~/.ssh/id_rsa.pub

Check SSH Configuration to handle permission denied (publickey) error

You should check the SSH configuration files to ensure that the server is configured to accept public key authentication. The following lines should be present in the SSH configuration file:

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

If these lines are missing, add them to the configuration file and save the changes.

Check Server Logs

If none of the above methods work, you should check the server logs to find out the cause of the problem. The server logs are usually located in the /var/log/auth.log or /var/log/secure file. You can view the logs using the following command:

$ tail -f /var/log/auth.log

Explore our comprehensive Basic Linux Commands Cheat Sheet for practical examples!"

The "SSH Permission Denied (publickey)" error is a common issue that users face while using SSH. There are several methods that you can try to resolve the issue, including checking the SSH agent, key permissions, SSH configuration, and server logs. By following these methods, you can quickly fix the "Permission Denied (publickey)" error and access your remote server.

This error message usually means that the SSH server is rejecting your authentication attempt because it doesn't recognize your SSH key or doesn't have permission to use it. 

This can happen when the SSH key is expired or has been removed from the authorized_keys file on the server. Another possible cause is that the server's SSH configuration has changed, such as disabling password authentication, which can cause the server to reject any authentication other than SSH keys. 

Yes, this error message is specific to SSH key authentication. You'll see a different error message if you're using password authentication and receive an authentication error.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.