Resolving the 'Server Refused Our Key' Issue When Connecting to Amazon Linux EC2 AWS Image from Putty

Resolving the “Server Refused Our Key” Issue When Connecting to Amazon Linux EC2 AWS Image from Putty
Whether you’re a seasoned data scientist or a software engineer, you’ve probably encountered the “Server refused our key” error while trying to connect to an Amazon Linux EC2 AWS image from Putty. This article offers a step-by-step guide on how to resolve this issue.
What is the “Server Refused Our Key” Error?
The “Server refused our key” error typically occurs when you attempt to connect to your EC2 instance using SSH keys, but the server rejects the key. This could be due to several reasons including incorrect permissions, improper key format, or incorrect SSH configurations on your EC2 instance.
Step 1: Ensuring the Correct SSH Key Format
Putty uses its own format for SSH keys — .ppk
(Putty Private Key). If you’re using a key in another format (like the .pem
file provided by AWS), you’ll need to convert it using a tool called Puttygen.
puttygen my-key-pair.pem -o my-key-pair.ppk
This command converts your .pem
file to a .ppk
file that Putty can use.
Step 2: Verifying SSH Key Permissions
Your SSH keys should have the correct permissions set. The private key file should only be accessible by the owner. You can ensure this by running the following command:
chmod 400 my-key-pair.pem
Step 3: Checking SSH Configurations on EC2
SSH configurations on your EC2 instance could also cause this error. AWS recommends the following settings in your /etc/ssh/sshd_config
file:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
You can check these configurations by connecting to your instance using EC2 Instance Connect or AWS Systems Manager.
Step 4: Verifying the Public Key on EC2
Finally, ensure that your public key exists in the ~/.ssh/authorized_keys
file on your EC2 instance. If it’s not there, you can add it using EC2 Instance Connect or AWS Systems Manager.
echo "your-public-key" >> ~/.ssh/authorized_keys
This command appends your public key to the authorized_keys file.
Recap
Here’s a recap of the steps to resolve the “Server refused our key” issue:
- Convert your SSH key to the
.ppk
format using Puttygen. - Ensure your keys have the correct permissions.
- Check the SSH configurations on your EC2 instance.
- Verify your public key on EC2.
By following these steps, you should be able to resolve the “Server refused our key” error when connecting to your Amazon Linux EC2 AWS image from Putty. If you’re still facing issues, don’t hesitate to reach out to AWS Support for help.
Takeaway
While this issue can be frustrating, it’s usually simple to fix. By ensuring you’re using the correct SSH key format, setting the proper permissions, and verifying your SSH configurations and public key on EC2, you can successfully connect to your EC2 instance from Putty.
Don’t let a server key refusal stand in the way of your data science or software engineering projects. With these simple steps, you’re well-equipped to handle this issue and keep your work on track.
About Saturn Cloud
Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.