Introduction
Bạn đang xem: How to Troubleshoot SSH Permission Denied Error
The SSH Permission Denied error often occurs when permission-related settings are modified on the SSH server. This error may occur after a package installation or when creating new users. In this tutorial, we will guide you through troubleshooting the SSH Permission Denied error and help you reconnect to your SSH server.
Xem thêm : Forgot your HBO Max password? Follow our password reset guide
Prerequisites
Before we proceed, make sure you have the following:
- SSH client on your local machine and SSH server on the remote system.
- A user account to access the remote server (for password-based login).
- A user account with sudo or root privileges.
What Causes SSH Permission Denied Error?
The SSH Permission Denied error occurs when trying to SSH into a server and can be displayed as “Permission denied (publickey,gssapi-keyex,gssapi-with-mic)”. This error message indicates that the attempted authentication methods failed during the connection initiation. While it suggests that the public key is the issue, it can be misleading.
There are two common reasons for this error:
- SSH server configuration file (sshd_config): This file contains the SSH server configuration. Changes to this file can lead to the Permission Denied error.
- Insufficient permissions in the authorized_keys file: The authorized_keys file contains a list of public keys for clients allowed to SSH into the server. If the system cannot read from this file, it results in the Permission Denied error.
How to Fix SSH Permission Denied
Xem thêm : 6 Top Invoicing Tips for Construction Professionals
Here are two solutions that you can try to fix the SSH Permission Denied error. These solutions require performing steps on the server-side. Open the terminal on your server and follow the instructions below.
Solution 1: Enable Password Authentication
If you want to use a password to access the SSH server, you can fix the Permission Denied error by enabling password login in the sshd_config file. Follow these steps:
- Open the sshd_config file in a text editor (such as nano):
sudo nano /etc/ssh/sshd_config
- Locate the PasswordAuthentication line and ensure it ends with “yes”.
- Find the ChallengeResponseAuthentication option and disable it by adding “no”.
- If any lines are commented out, remove the “#” to uncomment them.
- Save the file and exit.
- Restart the SSH service by running the following command:
sudo systemctl restart sshd
Solution 2: Change File System Permissions
Using password-based login as the SSH authentication method is not recommended for security reasons. This solution troubleshoots the public key authentication method. Follow these steps:
- Open the sshd_config file in a text editor:
sudo nano /etc/ssh/sshd_config
- Ensure the following options are set as specified:
PermitRootLogin no PubkeyAuthentication yes
- Comment out the GSSAPI-related options by adding “#” at the beginning of the lines:
#GSSAPIAuthentication yes #GSSAPICleanupCredentials no
- Make sure the UsePAM line is set to “yes”:
UsePAM yes
- Save the file and restart the SSH service:
systemctl restart sshd
- Check the permissions in your home folder:
ls -ld
- If the owner’s permissions are not set to read, write, and execute (drwx-), use the chmod command to change them:
chmod 0700 /home/[your-username]
- Go to the .ssh folder and check the permissions:
ls -ld
- The .ssh folder should also have read, write, and execute permissions for the file owner. To enforce them, use chmod again:
chmod 0700 /home/your_home/.ssh
- Check the permissions of the authorized_keys file in the .ssh folder:
ls -ld authorized_keys
- The file owner should have read and write permissions. Set them using chmod:
chmod 0600 /home/[username]/.ssh/authorized_keys
- Now try logging in with the key pair again. A successful login attempt should confirm that the issue is resolved.
Frequently Asked Questions
Q: What is the SSH Permission Denied error?
A: The SSH Permission Denied error occurs when there are issues with authentication during an SSH connection attempt. It is often displayed as “Permission denied (publickey,gssapi-keyex,gssapi-with-mic)”.
Q: What causes the SSH Permission Denied error?
A: The error can be caused by misconfigurations in the SSH server (sshd_config) or insufficient permissions in the authorized_keys file.
Q: Can I use password authentication to fix the SSH Permission Denied error?
A: Yes, enabling password authentication in the sshd_config file can be a solution. However, using public key authentication is generally more secure.
Q: Are there any security risks associated with password-based login for SSH?
A: Yes, password-based login for SSH is less secure compared to public key authentication. It is recommended to use public key authentication whenever possible.
Conclusion
By following the steps provided in this tutorial, you should be able to troubleshoot and fix the SSH Permission Denied (publickey,gssapi-keyex,gssapi-with-mic) error. Once resolved, you will be able to successfully SSH into your server. For more helpful articles and tutorials, visit Eireview.
Nguồn: https://eireview.org
Danh mục: Technology