SSH from local machine to instance keeps timing out. Have read troubleshooting guide

,

I am trying to ssh on to an Ubuntu EC2 instance from my local machine:

ssh -i /path/to/key.pem ubuntu@ec2-100-215-34-46.region-1.compute.amazonaws.com

(removed sensitive details)

However, it is timing out. I have a very basic AWS setup:

-One security group (default)

-Single VPC

-No subnet preference (uses the public availability zone one)

-Single key-pair

I have read this troubleshooting guide:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#TroubleshootingInstancesConnectionTimeout

My security group rules allow all incoming traffic, on all ports. Allows all outgoing traffic, all ports.

The route table for the instance’s subnet contains a rule for 0.0.0.0/0 with target to an internet gateway, which contains my VPC and is “attached” state.

The network ACL for the subnet includes rule #100 which allows all traffic, all protocols. Same for outbound.

I have waited until my instance passes both checks.

I created an instance without a key pair, just to check and I couldn’t SSH to that either. So it’s not the key pair.

Does anyone know what else it could be?

Do you have enableDnsSupport and enableDnsHostnames enabled for your VPC? The hostname ec2-100-215-34-46.region-1.compute.amazonaws.com doesn’t have an A record out in the world, which is maybe why you can’t resolve it.

Also, wild question, but 100.215.34.46 seems to belong to T-Mobile, not AWS. Is it a Wavelength instance? That’d be crazy because I thought only Verizon provides those.

RE the last point- I made up that address for security reasons, didn’t want to post the real address :slight_smile:

Should I still check your first point now you know the IP address I posted isn’t my real one?

DNS hostnames and DNS resolution is enabled on my VPC. I cannot see DNS support.

You connect and then timeouts? Or it preventa You from connecting?

I execute the command. it never completes and then eventually it reports the connection timed-out.

How about chmod 400 keypair.pem?

you need to add ssh port 22 to the security group.

“ssh -v” will tell you at least where it is hanging - on the connect, after connect before login, etc.

I get this but I don’t really understand what it means tbh:

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile ‘~/.ssh/known_hosts’ → ‘/home/user/.ssh/known_hosts’
debug3: expanded UserKnownHostsFile ‘~/.ssh/known_hosts2’ → ‘/home/user/.ssh/known_hosts2’
debug2: resolving “ec2-1.2.3.4.aws-region.compute.amazonaws.com” port 22
debug3: resolve_host: lookup ec2-1.2.3.4.aws-region.compute.amazonaws.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to ec2-1.2.3.4.aws-region.compute.amazonaws.com [1.2.3.4] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10

I did 777. In fact, I also created an instance without a keypair and I couldn’t ssh to that either.

Nope, it’s in a public subnet with an internet gateway. No NAT gateway required here.

OP, can you check the public IP of the instance – make sure it’s getting one. You aren’t attempting to ssh to the private IP address, are you?

I haven’t changed anything from the AWS default for Security Groups or VPC. When I look at the SG rules, it seems to imply all traffic is allowed in.

I need a a NAT gateway? This wasn’t mentioned in the troubleshooting guide though, i don’t think?

Stop troubleshooting with ssh. This is a network problem, not an app problem. Stop looking at dns, this is a network problem, not a dns problem. Get your public IP, you ought to assign an elastic ip which is free but you don’t have to you can get a random one each time (but that seems silly). See if you can open a connection to tcp/22. Probably not. What ami are you using? Some amis themselves block tcp/22 by default. If you haven’t start with a basic amazon linux 2 ami out of the box no changes. Don’t get caught up in stuff way above the basics of networking at a higher level protocol before you cover the connectivity issue.

Edit: another person mentioned and I agree, you hid your ip (probably not good practice to post make up IPs though on the internet that don’t belong to you, x.x.x.x is fine) but if that isn’t the public one that is obviously your problem.

It’s trying to connect, but not getting further than that. So it’s back to a networking problem.

If the security group allows everything from anywhere, can you ping the public IP? Do you have any network ACLs? There aren’t any by default, but they come in play before the security groups.

ssh doesn’t like it is the permissions on the .pem are too broad

https://unix.stackexchange.com/questions/115838/what-is-the-right-file-permission-for-a-pem-file-to-ssh-and-scp

Does the AMI you’re using have 22 open by default? I have seen a few that have iptables or similar enabled and traffic blocked…

Maybe consider Instance Connect as well.

Ping isn’t working either. I do have network ACLs, the incoming has: all traffic, all protocol, all port range, source 0.0.0.0/0 = allow. Anything else reject. Outbound has identical rules.