Unable to connect to amazon EC2 instance via PuTTY

15,679

Solution 1

Things to check when trying to connect to an Amazon EC2 instance:

  • Security Group: Make sure the security group allows inbound access on the desired ports (eg 80, 22) for the appropriate IP address range (eg 0.0.0.0/0). This solves the majority of problems.
  • Public IP Address: Check that you're using the correct Public IP address for the instance. If the instance is stopped and started, it might receive a new Public IP address (depending on how it has been configured).
  • VPC Configuration: Accessing an EC2 instance that is launched inside a Virtual Private Cloud (VPC) requires:
    • An Internet Gateway
    • A routing table connecting the subnet to the Internet Gateway
    • NACLs (Network ACLS) that permit through-traffic

If you are able to launch and connect to another instance in the same subnet, then the VPC configuration would appear to be correct.

The other thing to check would be the actual configuration of the operating system on the instance itself. Some software may be affecting the configuration so that the web server / ssh daemon is not working correctly. Of course, that is hard to determine without connecting to the instance.

If you are launching from a standard Amazon Linux AMI, ssh would work correctly anytime. The web server (port 80) would require installation and configuration of software on the instance, which is your responsibility to maintain.

Solution 2

Ajay,

Try this. Go to your VPC dashboard. Click on Network ACLs - on the associated acl, update your Inbound Rules to allow SSH access on port22.

Share:
15,679
Ajay Kulkarni
Author by

Ajay Kulkarni

#SOreadytohelp Rules Smash keyboard. Come up with beautiful products, no matter what happens I am nerdier than 97% of all people. Are you a nerd? Click here to take the Nerd Test, get nerdy images and jokes, and talk on the nerd forum! http://www.nerdtests.com/images/ft/nq/4fbf3d9fe6.gif https://akulkarni9.github.io/#/

Updated on August 17, 2022

Comments

  • Ajay Kulkarni
    Ajay Kulkarni over 1 year

    I created a new instance of Amazon EC2 in Amazon Web Services (AWS) by referring to the documentation. I even added a SSH rule like this:

    Port: 22  
    Type: SSH  
    Source: <My IP address>/32
    

    I downloaded the .pem file, converted it into .ppk file by using PuTTYGEN. Then I added host name in PuTTY like this:

    ec2-user@<public_DNS>
    

    I selected default settings, added that .ppk file to PuTTY, logged in and I got this error:

    PuTTY error

    Even trouble shooting link didn't help me.
    I'm also getting this error in system logs:
    img1

    How can I connect to my Amazon EC2 instance via PuTTY?

    • helloV
      helloV over 8 years
      Is it Ubuntu Linux or some other distro?
    • Volkan Paksoy
      Volkan Paksoy over 8 years
      Do you any response when you try telnet like this: telnet 52.27.219.7 22 ?
    • Ajay Kulkarni
      Ajay Kulkarni over 8 years
      @helloV: it is amazon linux HMV(Fedora)
    • Ajay Kulkarni
      Ajay Kulkarni over 8 years
      @VolkanPaksoy: I got this error: Connecting To 52.27.219.7...Could not open connection to the host, on port 23: Connect failed. I deleted my old instance and created new instance with the public ip 52.27.219.7.
    • Volkan Paksoy
      Volkan Paksoy over 8 years
      @AjayKulkarni: Port has to be 22, not 23. If still it doesn't work try allowing access from everywhere 0.0.0.0/32 temporarily. If it works then it has something to do with your IP. Make sure you still have the same external IP
    • Ajay Kulkarni
      Ajay Kulkarni over 8 years
      I tried telnet 54.68.184.49 22 where 22 is the port number. I got this error: Connecting To 54.68.184.49...Could not open connection to the host, on port 22: Connect failed. I set ip to 0.0.0.0/32, and telnet didn't connect to the public ip. I'm updating the question, wait
    • erik258
      erik258 over 2 years
      0.0.0.0/32 is just the ip 0.0.0.0 - that's never going to be the source of any traffic. 0.0.0.0/0 is any IP. Better to put in your IP because if SSH is open to all IPs you will have folks attempting to use it to access your system.
  • John Rotenstein
    John Rotenstein over 8 years
    Ajay, is your instance in a public subnet? If not, it would be unable to access the Internet, which could explain the failed cloud-init configuration and your inability to login. Look at the configuration of the subnet and ensure that it is routing through an Internet Gateway.
  • Abhi
    Abhi over 6 years
    AWS Help Desk Answet: Network connectivity to an EC2 instance is not enabled by default. You need to make some configuration changes in your VPC in the AWS management console. aws.amazon.com/premiumsupport/knowledge-center/…
  • stdunbar
    stdunbar almost 4 years
    What is "my ip"? This might help but some details would be good.
  • kon19
    kon19 almost 4 years
    @stdunbar In the INBOUND RULES Add a role as a SSH If you don't have yet and make the SOURCE from ANYWHERE then save it and try to log in from the CLI. Then go back and put your own IP address or an custom IP for security reasons. MyIP means your current IP. Look at the screenshot i.ibb.co/b7w4BBk/889.jpg