SSH to Amazon EC2 instance using PuTTY in Windows
Solution 1
I assume that the OP figured this out or otherwise moved on, but the answer is to use ubuntu
as the user (if the server is ubuntu).
Solution 2
1) Make sure you have port 22 (SSH) opened in Security Group of EC2 Instance.
2) Try connecting with Elastic IP instead of public DNS name.
I hope you have followed these steps Connecting EC2 from a Windows Machine Using PuTTY
Solution 3
Another situation where I got the "Server refused our key" error when using putty, from windows, to ssh to an EC2 instance running ubuntu:
The private key was wrongly converted from .pem to .ppk.
puttygen has two options for "converting keys".
- Load your .pem file into puttygen using the File->Load Private Key option and then save as .ppk file using the Save Private Key Button.
-
DO NOT use the menu option Conversions->Import Key to load the .pem file generated by EC2.
See the puttygen screenshots below, with the two menu options marked.
Solution 4
Check the username, it should be "ubuntu" for your machine. Check if traffic is enabled on port 22 in Security group. Check if you are using the correct url i.e ubuntu@public/elasticip
Solution 5
You won't face this error if you SSH AWS directly using ".pem" file instead of converted ".ppk" file.
1) Use Git Bash instead of putty. Since you can run all the Linux commands in Git Bash. By installing Git you get to access Git Bash Terminal
2) Right click from the folder where you have ".pem" and select "Git Bash Here".
3) Your key must not be publicly viewable for SSH to work. So run "chmod 400 pemfile.pem".
4) Connect to your instance using its Public DNS - "ssh -i "pemfile.pem" [email protected]"
5) Make sure to whitelist your Network IP for SSH in your_instance->security_group->inbound_rules
konkani
Updated on December 02, 2020Comments
-
konkani over 3 years
I am a newbie to Amazon web services, was trying to launch an Amazon instance and SSH to it using putty from windows. These are the steps I followed:
Created a key pair.
Added a security group rule for SSH and HTTP.
Launched and instance of EC2 using the above key pair and security group.
Using PuTTYgen converted the
*.pem
file to*.ppk
Using putty tried connecting to the public DNS of the instance and provided the
*.ppk
file.
I logged in using 'root' and 'ec2-user', and created the PPK file using SSH1 and SSH2, for all these attempts I get the following error in putty,
"Server refused our key"
Can you guys please help, any suggestions would be greatly appreciated.
-
Coder about 11 yearsUpdate: I have since created a "cloud formation" setup and have SSH'd fine. This time I used the template that allows you to specify a key-pair. Many of the stock templates don't allow that, which as you don't seem to be able to add the key-pairs after creation, means that you can never SSH.
-
Barak almost 11 yearsPoderosa needs the original pem file, but the converted one created by puttygen
-
Barak almost 11 yearsPoderosa needs the original pem file, NOT the converted one created by puttygen
-
Rig over 10 yearsThis is awesome. Not covered any obvious location I've found.
-
linuxeasy about 10 yearsConnecting with Elastic IP address worked in my case. I had lost access after creating and associating an ip-address. Thanks!
-
Jason about 10 yearsBrilliant :-) Two years on, and the Amazon documentation still has not been updated, and states that the user is "ec2-user" for all Amazon Linux AMIs. I would reasonably accept this as a answer, even if the OP has moved on.
-
Ryan Williams almost 10 yearsHe said the problem was authentication, not DNS resolution or firewall.
-
Vikas Kukreti about 9 yearsNice, you fulfilled my query too
-
jarmod almost 7 years@Jason The user for all Amazon Linux AMIs is ec2-user. Ubuntu is not Amazon Linux. "Amazon Linux" is a specific distribution of Linux from Amazon. Amazon also supplies other Linux distributions such as RHEL (user is ec2-user or root), CentOS (user is centos), Ubuntu (user is ubuntu or root), Fedora (user is ec2-user), and SUSE (user is ec2-user or root).
-
Osusara Kammalawatta over 3 yearsusing Git Bash instead Putty worked for me. Thank You!