How to Fix SSH Failed Permission Denied (publickey,gssapi-keyex,gssapi-with-mic)

Are you getting the SSH Permission denied error? If YES then don’t worry, you have come to the right place.

In this post, we will not teach you the easiest way to fix the SSH permission denied error but also explain all reasons that actually cause this issue.

For the unversed, SSH is a client or user account to access the remote server that has sudo or root privileges which means this client has read, write and execute permissions (Full Admin permissions).

But because of some unknown reasons, many people are getting the SSH Permission denied error.

Without any further ado, let’s get started:

What Causes SSH Permission Denied Error?

SSH Permission Denied error usually occurs when you play around with the file permissions.

Whenever this error occurs, you will get an error message like this,

Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

There are two common reasons that often cause this error. It is likely that you might be encountering this error because there is an issue in the sshd_config file.

For the unversed, this file contains the SSH server configuration. If you have an issue with this file, it means you have issues with SSH client configuration.

Another possible reason for getting the SSH Permission Denied error is that the authorized_keys file has insufficient permissions.

As I said earlier, users often encounter these types of errors when they play around with the file permissions.

You may have accidentally changed the authorized_keys file permissions which leads to this error.

However, you can fix this error by using the methods given below.

How to Fix SSH Failed Permission Denied

To make your work easier, we have mentioned two methods that can be used to fix the SSH failed permission denied error.

To know what those methods are and how they work, you need to keep reading this post.

Method 1: Enable Password Authentication

The best method to fix the SSH Failed Permission Denied error is to enable password login in the sshd_config file.

If you don’t know how to enable password login in the sshd_config file then follow the steps written below:

To do so, you need to open the sshd_config in our example we used the nano command to edit the text:

sudo nano /etc/ssh/sshd_config

In this file, you need to make sure two things,

First, find the PasswordAuthentication line and make sure this line ends with yes.

Next, find the ChallengeResponseAuthentication and disable it by adding no.

Once done, save and exit from the file. Now, restart the SSH service by using the following command:

sudo systemctl restart sshd

Method 2: Change File System Permissions

Insufficient file permissions also cause the SSH Failed Permission Denied error. To fix it, you need to make changes in file permissions.

To do so, you need to follow the steps written below:

First, open the sshd_config file using a text editor in our case we use nano:

sudo nano /etc/ssh/sshd_config

In this file, you need to make sure the following options are set as follows:

PermitRootLogin no
PubkeyAuthentication yes

Also, make sure the UsePAM is set to yes.

Once done, save the file and restart the sshd services using the following command:

systemctl restart sshd

Once done, head back to the home directory and check the permissions.

ls -ld

Your home directory needs read, write, and executer permissions to work.If your home directory does not have all three permissions then fire the following command to set the permission.

chmod 0700 /home/your_home/.ssh

As I mentioned above, you must be getting this error because the authorized_keys file does not have sufficient permissions.

This file required read-write permissions you can check its permission with;

ls -ld authorized_keys

If this file does not have read-write permissions then you can set the permissions using the following command:

chmod 0600 /home/[username]/.ssh/authorized_keys

After following these steps, you need to log in with the key pair again. If the output shows a successful login attempt then it means your problem is fixed.

That’s all you need to fix the SSH failed permission denied error.

Leave a Comment