DevOps

How can I Fix SSH Permission Denied?(publickey,gssapi-keyex,gssapi-with-mic)

Introduction

You will discover how or when to resolve the SSH Permission denied error as well as re-connect with your SSH server in this article.

Correct home directory permissions are necessary to avoid the SSH Permission Denied Error. As the default location for all SSH settings and verification files customized to each user

When changing the SSH settings on the server that affect permissions, the SSH Permission denied problem surfaces. Examples of typical cases involve adding new users and perhaps installing a new program.

What is Causing SSH Permission Denied?

What is Causing SSH Permission Denied?

Whenever you attempt to login into a server using SSH, you can receive the following error message:

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

The tried authentication methods that were unsuccessful at connection setup get listed in the bracket after the phrase “Permission denied.” The error makes the false assumption that public key authentication is the problem.

The sshd config file, which includes the configuration information for the SSH server, can be one cause of the issue. Another scenario is that there are inadequate permissions for the authorized keys file. The set of public keys for users who get allowed to SSH onto the server gets compromised in this file. The SSH Permission denied error is ultimately generated because the system is unable to read from the file.

Also Read: How to Save a File in Vim/Vi Editor?

How to fix SSH Permission denied?

How to fix SSH Permission denied?

There are server-side operations that could get conducted in both solutions. Open a terminal window on your server first, then carry out one of the techniques listed below.

Method 1: Make Password Authentication Available

The SSH Permission denied error can get resolved by enabling password login in the sshd config file when you get interested in employing a password to gain entry to the SSH server.

For this purpose, launch a text editor and open the file. The nano editor gets used in this example:

sudo nano /etc/ssh/sshd_config

Make Password Authentication Available

Locate the PasswordAuthentication section in the file and confirm that it gets finished with a yes.

Make Password Authentication Available

Disable the ChallengeResponseAuthentication feature by entering no after finding it.

Make Password Authentication Available

Delete the # after any lines that get commented out to make them uncommented.

Close the file after saving it.

By entering the following command, you can restart SSH permission:

sudo systemctl restart sshd

Make Password Authentication Available

Method 2: Modify the System Files Permissions

Due to various security issues, you’re not advised to use the password-based login for SSH authentication. While this fixes the publickey authentication mechanism, the alternative option could get considered.

At first, use a text editor to view the sshd config file:

sudo nano /etc/ssh/sshd_config

Modify the System Files Permissions

Check that the following settings are present in the file:

No, PermitRootLogin

Modify the System Files Permissions

Yes, PubkeyAuthentication

Modify the System Files Permissions

By placing the hash symbol to the line’s start, you can comment out the GSSAPI-related choices:

#GSSAPIAuthentication yes

Modify the System Files Permissions

#GSSAPICleanupCredentials no

Modify the System Files Permissions

Check to see if the UsePAM line gets adjusted to yes as well:

Yes to UsePAM

Modify the System Files Permissions

In order to restart the sshd function, save the file:

systemctl restart sshd

Modify the System Files Permissions

Once there, check the permissions by navigating to your home directory:

ls -ld

Modify the System Files Permissions

With the chmod function, you can modify your ownership rights to access, write, or execute (drwx———):

chmod 0700 /home/[your-username]

Modify the System Files Permissions

Navigate back to the.ssh directory and double-check the permissions now:

ls -ld

Modify the System Files Permissions

Read, write, as well as execution rights for the file user in this directory are also required. Utilize chmod once more to make them effective:

chmod 0700 /home/your home/.ssh

Modify the System Files Permissions

The authorized keys file can get found in the .ssh directory. To verify its SSH permissions, use:

ls -ld authorized keys

Modify the System Files Permissions

Both read and write access should be granted to the file administrator. To adjust them, utilize:

chmod 0600 /home/[username]/.ssh/authorized keys

Modify the System Files Permissions
Modify the System Files Permissions

Consider starting once more to log in using the key pair. An effective login effort can get seen in the results.

Also Read: 10 Easy Tips for Securing Your cPanel Server

Conclusion

You could perhaps resolve the SSH Permission Denied Error and get authorized SSH access to your server after following the instructions in the guideline. This guide addresses the measures required to fix your SSH Permission denied (publickey, gssapi-keyex, gssapi-with-mic) fault.

Arpit Saini

He is the Chief Technology Officer at Hostbillo Hosting Solution and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *