2

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:

  • Type=SSH Protocol=TCP Port=22 Destination=0.0.0.0/0 and
  • Type=All ICMP - IPv4 Protocol=ICMP Port=All Destination=0.0.0.0/0

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.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
dkhayutin
  • 33
  • 1
  • 7
  • Have you launched your instance in a public subnet or default VPC? – Marcin Mar 04 '21 at 04:30
  • @Marcin if i understand correctly, i originally created a VPC, and then two private subnets within it. Then i attached each instance to the respected subnets. – dkhayutin Mar 04 '21 at 04:33
  • Your instance must be in public subnet, not private, so that you can ssh to it directly. – Marcin Mar 04 '21 at 04:34
  • @Marcin my route table points to my vpc. Could this be part of the issue? – dkhayutin Mar 04 '21 at 04:38
  • I don't know how your VPC is setup. You can update your question with all its details. – Marcin Mar 04 '21 at 04:41
  • @Marcin within my setting i have DNS resolutions and hostname enabled, my network ACLs are both associated the private subnets i created in my vpc, and my route table is also pointing to my vpc that i created. Is there any other info i can provide? – dkhayutin Mar 04 '21 at 04:56

2 Answers2

2

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:

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • i have a public subnet setup, and unfortunately, the problem persists. – dkhayutin Mar 04 '21 at 06:21
  • @dkhayutin Can you please update your question with exact details of your VPC, route tables, security groups, NACLs and more. You can take screenshots if you want. – Marcin Mar 04 '21 at 06:25
  • @dkhayutin How did it go? Did you manage to connect? – Marcin Mar 06 '21 at 06:03
  • Marcin sorry for the delay in responding. Yes, it turns out that the MAJOR issue was that the subnets i had added in were not properly added to my route table. Seemed to solve the issue and i was able to then SSH! – dkhayutin Mar 11 '21 at 15:45
0

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

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470