The Secure Shell (SSH) key is the access credential for SSH protocol. Although the SSH protocol supports multiple approaches for authentication, the Public key is considered one of the best ways that help in automated and interactive connections.

While working on the unsecured open networks, the SSH protocol helps for remote connections among different devices. Using this, users can transfer the files remotely and also manage the network.

As there are multiple devices on the unsecured networks, the SSH uses a set of keys, i-e Private Key and Public Key, to create a secure connection between devices remotely.

The Difference between a Private key and a Public key is that a Private key is specifically for the user only as an authentication key, and we can also call it an identity key. The Public key, also termed an authorized key, is placed on the server (host); anyone having the Public Key can encrypt data and make connections over SSH protocol.

Keep in mind that each key is unique and only works with the same pair of keys.

How do I fix SSH permission denied Public Key:

When working with the SSH keys, permission denied public key error is the frequently occurring error.

This guide will show you the possible error you might face and their quick solutions.

Solution1: Enable Password Authentication:

The first solution is to enable the password login to access the SSH server. For this, open the sshd/config file in the terminal and configure the Password Authentication:

$ sudo nano /etc/ssh/sshd_config

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/1-11.jpg" data-lazy- height="56" src="data:image/svg xml,” width=”959″>

Scroll down until you get the “PasswordAuthentication” line and check if it is set as “yes”:

PawordAuthentication   yes

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/2-11.jpg" data-lazy- height="536" src="data:image/svg xml,” width=”805″>

Once the file is edited. Save it and restart the ssh service using the command:

$ sudo systemctl restart sshd

Solution 2: Configure the Permissions of File System:

Due to security issues, sometimes it is not recommended to access password authentication.

The next thing you can do is set the Public key Authentication method.

In the sshd/config file, search for the following lines and set them as mentioned:

PermitRootLogin    no

PublicKeyAuthentication   yes

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/3-11.jpg" data-lazy- height="56" src="data:image/svg xml,” width=”959″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/4-9.jpg" data-lazy- height="533" src="data:image/svg xml,” width=”806″>

Also, check that “UsePAM” is set to “yes”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/5-9.jpg" data-lazy- height="579" src="data:image/svg xml,” width=”965″>

Save the modifications and restart the ssh service:

$ sudo systemctl restart sshd

Solution 3: Set Directory Permission:

Use the “-ld’ command to check the permission of the “.ssh” file that contains “authorized_keys”:

$ ls -ld .ssh/authorized_keys

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/6-6.jpg" data-lazy- height="86" src="data:image/svg xml,” width=”967″>

The .ssh folder must have read and write permission, and to set it, use the following command:

$ chmod 600 /home/wardah/.ssh/authorized_keys

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/7-5.jpg" data-lazy- height="65" src="data:image/svg xml,” width=”965″>

Conclusion:

The Secure Shell (SSH) protocol has multiple authentication approaches, and Public Key is one of them. The SSH uses a set of keys, Public key and Private key, to make connections over protocol. The public key is placed on the Host Server; anyone having the public key can encrypt data and make connections remotely.

While working with the public key, the permission denied error is the most repeatedly occurring error people usually faced. You have learned multiple approaches from this guide on how to resolve SSH permission denied public key.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/81ddc0268829514e304c7a0bfa2cc3f8?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.