Sign in
Log inSign up
How to Fix Amazon AWS EC2 instance timeout while trying to connect (Using Putty)

How to Fix Amazon AWS EC2 instance timeout while trying to connect (Using Putty)

My First Major Challenge as a Beginner in Cloud Engineering (With SheCodeAfrica Cloud School)

Adeyemi Misturah's photo
Adeyemi Misturah
·Sep 2, 2021·

4 min read

SheCodeAfrica Cloud School Cohort2 started on August 9, 2021, we were given a written learning approach, and everything seems easy at first until I got to the part of building cloud servers, I will be discussing the full challenge and how I overcome it.

Building my server on AWS and launching the instance was a piece of cake until I wanted to connect to my server with SSH using an SSH client(putty), I installed Putty and followed many tutorials to connect to AWS server using Putty but every time I tried to log in I found an error as shown in the screenshot below:

errorr.PNG

So, I did a lot of research online and found many solutions and reasons for this problem. Some people suggested checking and disabling all firewalls while others suggested other solutions. Many solutions have failed to address this issue.

However, It was a security group issue in the end. So if you try to connect to your instance using an SSH client like Putty and all the prerequisites are met but you are getting this error message :

(Network error: Connection timed out or Error connecting to [instance], reason: -> Connection timed out: connect)

you should check your Aws security group rules that are attached to your Ec2 Instance, Because you need a security group rule that allows inbound traffic from your public IPv4 address on the proper port for SSH connection, you have to enter Port 22 as shown in Screenshot.

inbounds.PNG

To do this you can follow the below-given steps:

  • In the navigation pane, choose Instances, and then select your instance.
  • In the Description tab at the bottom of the console page (as shown below), next to Security groups, select view inbound rules to display the list of rules that are in effect for the selected instance.

Security groups.PNG

When you select view inbound rules, a window will appear that displays the port to which traffic is allowed. Verify that there is a rule that allows traffic from your computer to port 22 (SSH). If you already allow port number 22 in your AWS Security Group then check your connection with Aws Ec2 instance through the Telnet command.

After following the above steps, I was able to SSH into my instance successfully, I went to bed that night feeling very happy, only to wake up the following morning and I wanted to try reloading my session and I started getting the same error again. I was devastated, sad, and stuck because I don't even know where to start from. I dropped my PC and went back to bed(I Heard sleeping helps in solving issues like that Lol). Then I stood up like an hour later and started making more researches on the internet then I figured out that each time you restart your instance, a new IP address (and hostname) will be assigned to your Ec2 Instance, So I had to calm down and do the following :

  • I made sure the EC2 instance is running.
  • I checked my security group rules. Since I need a security group rule that allows inbound traffic from your public IPv4 address on the proper port (Like I did in the previous steps).
  • I also checked the network access control list (ACL) for the subnet. The network ACLs must also allow inbound and outbound traffic from your local IP address to the proper port. The default network ACL allows all inbound and outbound traffic.
  • In addition, I checked the routing table for the subnet. Since I also need a route that sends all traffic destined outside the VPC to the internet gateway for the VPC.
  • And finally, I made sure I encrypted the public key correctly.

After doing all the stated above I was able to SSH into my Instance again and anytime I encounter that same error I just follow the same steps and it has been working for me.

I really hope this article helps a Cloud Engineering newbie like me that encounters this same issue on their first try of creating an Instance.

PS: If your computer is in a corporate network, ask your network administrator if the internal firewall allows internal and external congestion from your computer in port 22 (for Linux cases) or port 3389 (for Windows conditions). If you have a firewall on your computer, make sure it allows incoming and outgoing traffic from your computer to port 22 (for Linux cases) or port 3389 (for Windows situations).