Solutions to fix SSH Failed Permission Denied

ssh failed permission denied

If you use SSH to connect to servers, you might encounter the “SSH Permission Denied” error. This error usually happens when there are SSH key management or authentication issues. Although SSH is commonly used for secure connections to remote servers, encountering this error can block access.

Now, let us see how to fix the SSH Failed Permission Denied,

Step1: Diagnose the Issue

Use your SSH Client’s Verbose mode to receive a proper and detailed error message.
It is possible to achieve this by adding the -v or -v flags to your initial SSH command in your terminal.

ssh -v username@hostname

For server-side errors, check the server error log for important errors and entries related to your connection problem. You can also check the error with the following command on a Debian-based system:

cd /

cd  /var/log/auth.log

Step2: Check for the client-side errors

  • Check that the user connecting to the remote server has the required permissions to access the server.
  • Check the SSH connection’s access credentials and double-check them to ensure they are correct.
  • Make sure you have the most recent SSH client installed on your machine.

The command format should be like this for Debian-based systems:

sudo apt update

sudo apt upgrade

After updating, restart SSH to apply the changes.

sudo systemctl restart ssh

Method 1: Enable Password Authentication

Password authentication is an important phase in accessing the SSH server. On Linux systems, you can fix the permission denied problem by enabling password login in the sshd_config file.

  1. Open the sshd_config file in a text editor, such as vi or vim on Linux.
  2. After opening the file, check the “PasswordAuthentication” line and make sure it finishes with yes in the text editor.
  3. Also, check the “ChallengeResponseAuthentication” in the file to disable it by writing no. Remove the hash sign # from commented lines to uncomment them.
  4. Save and exit the file (Use Ctrl+S and Ctrl+X to save and exit when using Nano type)
  5. Use the below command to restart the SSH Service:
sudo systemctl restart sshd

 

Method 2: Change the File System Permission

Due to security concerns, using password-based SSH authentication is not recommended. It is recommended to use public key authentication. To switch to this method, modify the permissions as follows:

  1. Open the sshd_config file with a text editor
sudo nano /etc/ssh/sshd_config
  1. Ensure that the following settings are set in the file
PermitRootLogin no

PubkeyAuthentication yes
  1. To comment on the GSSAPI-related options, enter the hash symbol at the beginning of the line.
#GSSAPIAuthentication yes

#GSSAPICleanupCredentials no
  1. Check the UsePAM line is set to yes
UsePAM yes
  1. Save and restart the SSH Service.
sudo systemctl restart sshd

Now, go to your home folder and check the permissions

cd home

ls -ld
  1. If your owner permissions are not set to read, write, and execute (drwx——), change them using the chmod command
chmod 0700 /home/[your-username]

Again, go to your home folder and check the permissions.

cd .ssh

ls -ld

This directory should allow the file owner to access, write, and execute. To implement them, use chmod command again.

chmod 0700 /home/your_home/.ssh

To resolve SSH “Permission Denied” errors, start by using verbose mode to view detailed error messages and check server logs for additional information. Verify that the user has the correct permissions and the SSH credentials are accurate. Ensure your SSH client is up-to-date. If needed, enable password authentication temporarily. For better security, switch to public key authentication, and adjust file permissions accordingly. If you need any technical help to fix the error, feel free to contact us for support!

Also check: 2 Methods to Back Up the ESXi Host Configuration

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

 

Written by actsupp-r0cks