After changing permission-related parameters on the SSH server How to Fix SSH Failed Permission Denied? the problem manifests itself. The installation of a new product or the creation of new users are typical cases.
You will discover How to Fix SSH Failed Permission Denied? error and reconnect to your SSH server in this article.
- SSH server on the distant system and SSH client on the local machine
- A username and password for the remote server (for password-based login)
- A user account with root or sudo access
How to Fix SSH Failed Permission Denied
When attempting to SSH onto a server, the SSH Permission denied error appears:
- Refusal of permission (publickey, gssapi-keyex, gssapi-with-mic)
The tried authentication methods that were unsuccessful at connection initiation are listed in the bracket after the phrase “Permission denied.” The error gives a false impression that the public key is the problem.
SSH server configuration file sshd config might be a contributing factor in the error. The authorized keys file may also not have enough permissions, which is another issue.
The list of public keys for clients who are permitted to SSH onto the server is contained in this file. The system cannot read from the file as a result, and the Permission denied error is returned.
How to fix SSH Permission denied?
Both solutions contain steps you need to perform on the server side. Start by opening the terminal on your server and proceed with one of the solutions below.
Solution 1: Enable Password Authentication
If you want to use a password to access the SSH server, a solution for fixing the Permission denied error is to enable password login in the sshd_config file.
To do this, open the file in a text editor. This example uses the nano editor:
sudo nano /etc/ssh/sshd_config
In the file, find the Password Authentication line and make sure it ends with yes.
Find the ChallengeResponseAuthentication option and disable it by adding no.
If lines are commented out, remove the hash sign # to uncomment them.
Save the file, then shut down.
By entering the following command, the SSH service can be restarted:
systemctl sudo restart sshd
Solution 2: Change File System Permissions
Using the password-based login as the SSH authentication method is not recommended due to security concerns. Therefore, the following solution may be preferable since it troubleshoots the public key authentication method.
First, open the sshd_config file using a text editor:
sudo nano /etc/ssh/sshd_config
In the file, make sure the following options are set as follows:
By adding the hash sign at the beginning of the line, you can comment out the GSSAPI-related options:
Yes for #GSSAPIAuthentication
Credentials for #GSSAPICleanup no
Additionally, confirm that the UsePAM line is set to yes:
Restart the sshd service after saving the file:
sshd systemctl restart
Go to your home folder now, and look at the permissions:
Use the chmod command to modify your owner permissions if they are not set to read, write, and execute (drwx———):
/home/[your-username] chmod 0700
Recheck the permissions in the. ssh folder now:
Additionally, the file owner should be able to read, write, and execute in this directory. Use chmod once more to enforce them:
/home/your home/.ssh chmod 0700
The authorized keys file is located in the. ssh folder. Verify its authorizations using:
authorized keys: ls -ld
Read and write permissions must be granted to the file owner. Use: to set them:
/home/[username]/.ssh/authorized keys chmod 0600
How to Fix SSH Failed Permission Denied file? Now attempt to log in once more using the key pair. A successful login attempt is shown in the output below.
The steps required How to Fix SSH Failed Permission Denied file? (publickey, gssapi-keyex, gssapi-with-mic) errors were covered in this tutorial. You should be able to correct the problem and successfully SSH onto your server by following the instructions in the guide.