SSH, an acronym for Safe Shell, is a distant protocol that’s broadly used to make distant connections to servers, community units, and different distant hosts that run the service. It makes use of a public/personal key pair to encrypt visitors between the consumer and the distant host.
When making a connection, you would possibly encounter the “ssh permission denied public key” error. On this information, we search to grasp the reason for this error and learn how to handle it.
Explanation for SSH Permission denied (publickey) Error
The basis reason for this error is usually a misconfiguration within the /and so forth/ssh/sshd_config file which is the default SSH configuration file.
One other perpetrator is inadequate permissions on the authorized_keys file on the distant system. The file comprises the general public keys of shopper programs allowed to SSH into the server.
With out a lot ado, allow us to try potential options to unravel this error.
Allow Password Authentication
As earlier identified, one of many causes attributed to this error is a misconfiguration of the /and so forth/ssh/sshd_config file. One of many flawed settings is the disabling of the password authentication characteristic. This may occur in case somebody is utilizing SSH Key-based authentication solely and for some cause, the personal key is just not current.
To deal with this error, edit the default SSH configuration file.
$ sudo vim /and so forth/ssh/sshd_config
Find the PasswordAuthentication
attribute and set it to sure
as proven beneath.
Save the adjustments and exit the configuration file. Then restart the SSH service for the adjustments to come back into impact.
$ sudo systemctl restart sshd
It’s best to now be capable to join seamlessly to the distant host.
Examine SSH Authorized_keys Permission
Typically, the error comes from incorrect permissions and possession of the ~/.ssh/authorized_keys file on the distant system.
The ~/.ssh/authorized_keys file is situated on the distant server. It comprises the general public SSH key from the shopper system connecting to it utilizing SSH-key authentication. Keep in mind that the personal key ought to stay on the shopper system and by no means be shared.
The authorized_keys file needs to be owned by the consumer on the distant system. As well as, the consumer ought to have learn and write permissions.
If this isn’t the case, set the permissions to the file as proven.
$ sudo chmod 600 ~/.ssh/authorized_keys $ ls -l .ssh/authorized_keys
Again on the shopper system, make sure that Public and Personal Keys have the right permissions.
- The Personal Key ought to have learn and write permissions just for the file proprietor.
- The Public Key ought to have learn and write permissions for the file proprietor and browse permissions for each the group and different world customers.
If this isn’t the case, configure the permissions as follows in octal format.
$ sudo chmod 600 ~/.ssh/id_rsa $ sudo chmod 644 ~/.ssh/id_rsa.pub
These are the 2 principal ways in which you should use to troubleshoot the “ssh permission denied public key” error. Have we left one thing else out? Do tell us within the remark part.