One of the most popular errors during operating with SSH keys is the: “AWS SSH permission denied (PublicKey)” error. This post will refer to you the different causes of this issue and present the rapid steps which you might deal with this problem. Let’s start with them below.
When will the “AWS SSH permission denied (PublicKey)” error happen?
This error “AWS SSH permission denied (PublicKey)” will appear when attempting SSH into the server, especially after modifying permission-related settings.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
After this error happens, we find out the root causes below:
1. The missing keys from your local computer.
2. The incorrect configuration in the sshd_config file.
3. The permissions for the authorized_keys file.
How to tackle this error?
Approach 1: Permit Password Authentication
If you expect to take a password to approach the SSH server, a way to tackle this problem is to permit password login in the sshd_config file.
First, open this file and use the nano editor like below.
sudo nano /etc/ssh/sshd_config
After opening the file, you will search for the ‘PasswordAuthentication’ line and ensure it can finish with ‘Yes’. Then, search for the ‘ChallengeResponseAuthentication’ option, and add ‘No’.
Afterward, you eliminate the hash sign # to uncomment them in case the lines are commented. Next, you save the file and exit.
Finally, you type the command below to reboot the SSH service.
Sudo systemctl restart sshd
That’s cool! We will make sure that your error will be removed successfully.
Approach 2: Disable ‘PublicKey’
To solve this error, you need to disable ‘PublicKey’. In other words, you open and edit the ssh configuration file.
PubkeyAuthentication yes #PasswordAuthentication yes
Next, you change the entries below:
#PubkeyAuthentication yes PasswordAuthentication yes
Please save and reboot the SSH service when customizing the configuration by typing the command below.
sudo systemctl restart sshd.service
If you are sure that the keys might be compromised, you could clear them or add the particular key to revoked list.
Approach 3: Set directory permissions and authorized keys
As for this solution, you should set the authorized_keys to 600 and the .ssh directory permissions to 700.
Let’s run the command below.
sudo chmod 700 ~/.ssh sudo chmod 600 authorized_keys
Then, you will realize that this error is solved completely in this case.
The guide presented you with how to troubleshoot different cases of the error: “AWS SSH Permission denied (PublicKey).” Lastly, ITtutoria hopes you can find it helpful in researching great solutions. Feel free to leave your feedback below if possible.
→ Tips On Solving The Error: “Permission denied. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources”