You want to apply a critical patch on your Linux servers. This has been done many times so it should not be a problem (probably). You attempt a connection to the remote server and you are greeted with an error message: SSH permission denied (publickey). This error message is now blocking you from accessing the remote server and can frustrate you. While it is easy to fix this error (which this article is about), we highly recommend understanding why this error message pops up, so that you are fully prepared the next time. In this article, we have explained the common reasons why this error message shows up and also the troubleshooting instructions.
Why is SSH important
In the Linux world that consistently faces malicious attacks, vulnerability exploits, and data integration threats, SSH is a savior. SSH is crucial for securely accessing and managing your remote servers. SysAdmins and SREs use SSH to perform their regular tasks such as file management, file transfers, patching, command execution, and many more with security. SSH allots a secure communication pathway to the remote servers so that any and all data are protected from unintended endpoints. In short, SSH is the key component to provide confidentiality and security when you work with remote servers.How does SSH do that? Through authentication mechanisms like public key authentication.
When would you see the SSH permission denied (Publickey) error message
Let us see the common reasons that are behind the SSH permission denied error message.
SSH Key pair mismatch
In SSH, secure communication happens through a pair of keys: private and public key. The private key is usually stored on the user’s device and used to authenticate the user by decrypting the data. The public key is used to encrypt the data which can only be decrypted by the respective private key. The public key is located in the
Incorrect SSH permissions
If the SSH keys or the
Public key not authorized
As explained earlier, the public key a user uses to authenticate should exist in the
SSH agent errors
An SSH agent is a program that contains the private keys and provides the keys to SSH sessions whenever required. If the SSH agent does not contain the private key or if the SSH agent is down, the authentication will fail.
“ssh_config” and “sshd_config” files incorrect settings
The “
Troubleshooting steps for SSH Permission Denied (PublicKey)
Step 1: Double check the SSH key pair. If required, use ssh-keygen to generate a new SSH key pair.
Step 2: Set proper permissions for SSH. If required, execute this command to set proper SSH permissions.
The command “
Step 3: Manually edit the “
Step 4: Restart the SSH agent and add the private key. Execute these commands to do so.
Step 5: Verify the SSH Configuration in
Let’s get started
Use these troubleshooting instructions to fix the SSH permission denied (publickey) error message and ensure seamless access to all your remote servers.
Related Articles
How to access remote servers using SSH (RedHat’s documentation)