“Permission denied (publickey)” error when connection over SSH

To explain this error we will have to first explain that SiteGround uses key-based authentication with SSH, replacing standard password authentication. Detailed information on SSH keys and key-based authentication is available in our article here.

In short, you cannot merely use a username or password to authenticate over SSH with SiteGround users. You will need a key pair, which consists of a public key and a private key. The public key is placed on your host server, and the private key on your own computer, where you will present it to the server in order to authenticate and initiate the SSH connection. Each pair of keys is unique, and each public key only works with the private key from the same pair.

The error "Permission denied (publickey)" seems straight forward in its context, as it clearly suggests that there is a problem with the SSH keys used for authentication. However, it can be easily misinterpreted that the problem is with the public key. It is important to understand that the error actually states that the public key found on your hosting account rejected the private key that you provided for authentication purposes. This doesn't mean that the problem is with the public key itself.

Most often this type of error comes up when using a wrong private key. The easiest way to confirm and resolve this is by generating a new key pair and connect using the new set of keys. A quick way to generate new keys is in cPanel, under SSH/Shell Access. The articles below also explain how to generate new SSH keys manually on various operating systems:

How to generate an SSH key pair on Linux
How to generate SSH keys on Mac OS
How to generate SSH keys on Windows using PuTTY

Apart from using an incorrect key or set of keys, there are several other situations that can lead to this type of error, all related the SSH connection details you are using. Public keys are stored per user on the server, so if you are using an incorrect SSH username, you would encounter the same type of error. If you are connecting to an incorrect or outdated IP/host, chances are there won't be a matching public key there for the private one you are presenting, and you would also end up with the same error. Therefore, if generating a new key pair did not resolve the problem, check your SSH connection settings. This article will direct you to the correct resource, that will guide you on how to log into your hosting account via SSH and where to find the correct connection details.

You find this article useful? Click here to learn more about SiteGround web hosting experts and what else we can do for you!