dkhayutin
dkhayutin

Reputation: 33

Cannot SSH in AWS EC2 Instance: Operation timed out

I have been stuck on this since last night. The command I am using is ssh -i myfile.pem ubuntu@publicIP.

I have changed the chmod to 400.

When I run the command in my terminal it doesn't do anything and then after about 30 seconds I see:

ssh: connect to host 18.234.225.93 port 22: Operation timed out

For my security groups, inbound I have selected:

Outbound is the same but one more row for all traffic at 0.0.0.0/0

I am unsure as to what else I can do to make this work, and whether or not this is an issue on my end or AWS. I have followed some step by step instruction that I have found on here such as How do I set up SSH access for an Amazon EC2 instance? but with little success. If anyone can help, I would appreciate it.

Upvotes: 2

Views: 1411

Answers (2)

Marcin
Marcin

Reputation: 238051

Based on your description in the comments.

Your VPC has only two private subnets. When you place an instance in a private subnet, as the name "private" suggests, there is no internet connectivity to it, nor it can connect by default to the internet.

To be able to directly ssh into your instance, it must be place in public subnet. So you would have to add such a subnet to your VPC, or convert existing private subnet into public.

For public subnet you need:

  • Internet gateway (IGW) attached to your VPC
  • a route table pointing 0.0.0.0/0 to the IGW
  • subnet should usually have Assign public IP enabled.

Example of a VPC with both public and private subnets is shown in:

Upvotes: 2

John Rotenstein
John Rotenstein

Reputation: 269091

When an SSH connection times-out, it is normally an indication that network traffic is not getting to the Amazon EC2 instance.

Things to check:

  • The instance is running Linux
  • The instance is launched in a public subnet, which is defined as having a Route Table entry to points to an Internet Gateway
  • The instance has a public IP address, which you are using for the connection
  • The Network Access Control Lists (NACLs) are set to their default "Allow All" values
  • A Security Group associated with the instance that permits inbound access on port 22 (SSH) either from your IP address, or from the Internet (0.0.0.0/0)
  • Your corporate network permits an outbound SSH connection (try alternate networks, eg home vs work vs tethered to your phone)

See also: Troubleshooting connecting to your instance - Amazon Elastic Compute Cloud

Upvotes: 0

Related Questions