Connection Time Out in AWS EC2

Connection Time Out in AWS EC2

 

Possible reasons for timeout when trying to access EC2 instance

  • The most likely one is that the Security Group is not configured properly to provide SSH access on port 22 to your i.p.
  • The local firewall configuration does not allow SSH access to the server.
  • The server is not started properly
  • Net connectivity
  • Wrong pem file / Host Name
  • Spelling mistake

 

When it times out or fails, check the following:

Security Group:

Make sure to have an inbound rule for tcp port 22 and either all ips or your ip. You can find the security group through the ec2 menu, in the instance options.

Routing Table:

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

Add Route to Routing Table
Destination: 0.0.0.0/0
Target: <Internet Gateway from earlier>

Elastic IP:

For an instance in a vpc, you 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. You can get an elastic ip in the ec2 menu (not instance menu).

Username:

Make sure you’re using the correct username. It should be one of ec2-user or root or ubuntu. Try them all if necessary.

Private Key:

Make sure you’re using the correct private key (the one you download or choose when launching the instance). Seems obvious, but copy paste got me twice.

Alternatively, Building everything back. This included:

  1. Create VPC
  2. Create Internet Gateway
  3. Attach Internet Gateway to VPC
  4. Create Routing Table
  5. Add Route to Routing Table
  6. Create Subnet