Linux Commands

How do I fix SSH permission denied public key

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

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

PawordAuthentication   yes

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

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

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

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

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

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

Syeda 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.