SSH to Amazon EC2 instance using PuTTY in Windows

57,821

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".

  1. 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.
  2. 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.

Correct menu option with puttygen Wring menu option with puttygen

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

Share:
57,821
konkani
Author by

konkani

Updated on December 02, 2020

Comments

  • konkani
    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:

    1. Created a key pair.

    2. Added a security group rule for SSH and HTTP.

    3. Launched and instance of EC2 using the above key pair and security group.

    4. Using PuTTYgen converted the *.pem file to *.ppk

    5. 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
    Coder about 11 years
    Update: 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
    Barak almost 11 years
    Poderosa needs the original pem file, but the converted one created by puttygen
  • Barak
    Barak almost 11 years
    Poderosa needs the original pem file, NOT the converted one created by puttygen
  • Rig
    Rig over 10 years
    This is awesome. Not covered any obvious location I've found.
  • linuxeasy
    linuxeasy about 10 years
    Connecting with Elastic IP address worked in my case. I had lost access after creating and associating an ip-address. Thanks!
  • Jason
    Jason about 10 years
    Brilliant :-) 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
    Ryan Williams almost 10 years
    He said the problem was authentication, not DNS resolution or firewall.
  • Vikas Kukreti
    Vikas Kukreti about 9 years
    Nice, you fulfilled my query too
  • jarmod
    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
    Osusara Kammalawatta over 3 years
    using Git Bash instead Putty worked for me. Thank You!