Reasons of timeout when trying to connect EC2 instance.

When we start an EC2 instance from AWS with our required services and settings, we expect to connect with the instance. We can run into timeout issues while connecting with AWS instance. There could be many reasons for this connection timeout issue. The following are some possible reasons for the connection timeout issue.

ssh -i "yourpemfile.pem" ubuntu@ec2-yourdomain.eu-west-1.compute.amazonaws.com

Where yourpemfile.pem is the pem file provided by AWS and ec2-yourdomain.eu-west-1.compute.amazonaws.com is the instance’s public domain.

As soon as we find our instance up and running we may want to SSH to the instance. The SSH attempt can run into a timeout issue. If we find timeout issue we can start checking the following steps one by one.

Security Group

We need to make sure to have an inbound rule for tcp port 22 to do the SSH. We can allow either all IPs or our own IP. You can find the security group through the EC2 menu, in the instance options.

Elastic IP

For instance, in a VPC, we need to assign a public elastic IP address and associate it with the instance. The private IP address can’t be accessed from the outside.

Routing Table

For a new subnet in a VPC, we need to change to a routing table that points 0.0.0.0/0 to internet gateway target. When we create the subnet in our VPC, by default it assigns the default routing table, which probably does not accept incoming traffic from the internet. We can edit the routing table options in the VPC menu and then subnets.

Username

We need to make sure that we are using the correct username. It should be one of ec2-user or root or ubuntu.

Private Key

When we are using private key we use the correct private key. We should double-check this if necessary.