Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't SSH into AWS EC2 instance

I can't SSH into my EC2 instances - I am getting a timeout error. I checked the security groups to ensure that SSH traffic is working. I checked the routing tables and ensured that they are connected to an internet gateway. I was able to SSH into the instances just an hour ago but no longer. I am connecting via Putty. I had the same timeout issue connecting before using ec2-user@domain which I solved by simply entering the ip address into the hostname field in Putty. At that point I was able to connect without a problem. I then created another EC2 instance and now I cannot connect to either instance. I have the .ppk file being correctly referenced in my Putty config. I tried connecting with a mac and copying the .pem file there. Is there anything else I can check? Also, why could I not type ec2-user@domain into the connection field in putty like the directions indicate. Is there something wrong with my AWS environment?

like image 498
Barodapride Avatar asked Mar 17 '19 21:03

Barodapride


1 Answers

The best way to diagnose an SSH problem is to launch a new instance in the same subnet, using the same security group. If this works, then the problem is related to the original instance.

The fact that you are receiving a timeout error indicates that your SSH client has been unable to reach the instance. The instance is not rejecting the connection (eg due to a keypair), it is the fact that the instance cannot be reached.

Things to check:

  • Confirm that the Public IP address is still current (it can change it the instance is stopped and started)
  • Confirm that the instance is in a public subnet, which means a subnet that has a Route Table pointing to an Internet Gateway
  • Confirm that the security group is permitting inbound SSH traffic (port 22) from your IP address (or even 0.0.0.0/0 for testing purposes)
  • Keep NACLs at default settings unless you understand them deeply
  • Make sure the instance is a Linux instance (Windows does not have SSH enabled)
  • Try it from a different network (eg home, office, tethered via your phone) because some corporate networks block SSH connections

As another test, you might want to temporarily create another VPC. Use the VPC Wizard to create a VPC with just a single, public subnet. Launch an instance and confirm that you are able to SSH into the instance.

like image 175
John Rotenstein Avatar answered Nov 11 '22 06:11

John Rotenstein