Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network.  

SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary.

There are several ways to use SSH:

  1. Using automatically generated public-private key pairs to encrypt a network connection and then use password authentication to log on. 
  2. Another is to use a manually generated public-private key pair to perform the authentication, allowing users or programs to log in without specifying a password. 

 

One of the most common errors when working with SSH keys is the permission denied (public key) error.

 

Here we will discuss the various reasons for this error and see how to fix these errors.

 

Error 1: Authorized Keys and Directory Permissions

 

One of the reasons for this error could be the permissions and ownership configured for the .ssh directory and authorized_keys file.

 

To fix this issue, set the .ssh directory permissions to 700 and the authorized_keys permissions to 600.

sudo chmod 700 ~/.ssh sudo chmod 600 authorized_keys

 

Error 2: SSH Incorrect Configurations

 

Another reason for the public key permission denied is a public key error in an incorrect configuration in the sshd_config file. To solve this issue, edit the /etc/ssh/sshd_config file and change the following entries.

#PermitRootLogin prohibit-password
#PasswordAuthentication yes

 

The above entries should be as shown below:

PermitRootLogin yesPasswordAuthentication yes

 

Save the configuration and restart the service:

sudo systemctl restart sshd.service

 

Error 3: Missing Keys

 

Another possible cause of the error could be missing keys from your local machine. If you have your keys added to the authorized_keys file of the server but are missing the corresponding private keys, this may cause an error.

 

To settle this issue, edit the ssh configuration file, disable public-key authentication, and enable password login, as follows:

PubkeyAuthentication yes
#PasswordAuthentication yes

 

Change To the following entries:

#PubkeyAuthentication yes 
PasswordAuthentication yes

 

Once you edit the configuration, save the file, and restart the SSH service:

sudo systemctl restart sshd.service

 

If you are sure that your keys have been compromised, you can remove them from authorized_keys or add a specific key to the revoked list in SSH.

 

Conclusion

I hope you have understood how to address various issues that are caused by the permission denied (public key) error in SSH. If this issue persists, consider other troubleshooting methods.

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)