Question - Can't SSH into an EC2 Instance

,

Hi all, so for some reason I can’t ssh into an Ec2 instance

Below is basically everything - its a Kali aws marketplace box “I killed this box so its not up right now”

  • I set up multiple rules the SG to allow ssh in and out to both my IP and anywhere.

  • I made sure the SG was assigned.

  • I allowed ping and couldnt ping

  • i ensure vpc had rules as well

  • I followed the rules to save the ppk key in putty

    • I downloaded the prem key
    • loaded the prem key in puttygen
    • saved the prem key without a password as a private key
    • loaded the prem key into putty per directions (SSH > AUTH)
  • I KNOW EXTERNAL SSH WORKS - I can ssh into azure.

  • this failed on both kalli and nessus

  • tried t2.med and t2.micro

  • Connection just times out???

  • tried on two different AWS accounts

    • 6 different instances
    • 2 rebuilt instances
    • 2 new SGs and VPCs
    • 2 New inbound and outbound rules
  • Tried in linux using the prem key and ssh -i

Theres got to be a simple fix and i really dont know what it is

Need to check subnets and route tables

Does the VPC you’re using have an internet gateway attached?

$ ssh -vvv -i /path/to/your/pem user@ip

Does it timeout?

it tries the key, then fails, then tries other keys, then fails for too many tries?

Do you have any overriding configuration in ~/.ssh/config?

Can you at least ping the service? (with netcat for example)

$ nc -vz ip 22

If ssh -vvv cannot connect or nc is not able to reach the socket, then it is routing/firewall/sg, if not, ssh -vvv will tell you what is wrong with the connection.

Route tables are the silent killers for people new to aws and especially demo labs. I feel like route tables are the answer to these questions 90% of the time

The other 10% is the dns host names checkbox

It’s usually something stupid. Here is what I did learning aws

Choose the vpc wizard, boot up a box and make sure it works.. Aws provisions everything for you.

Compare that to your vpc. Find the thing you missed.

Without one your VPC has no internet access.

Just use any EC2 instance for now, until the vpc is configured correctly .

How many availability zones, subnets and route tables do you have ?

Assuming you have one of each so most likely you need to add the 0.0.0.0/0 route to point to your internet gateway that is attached to your vpc ( if don’t have one then that’s the starting point )

https://aws.amazon.com/answers/networking/aws-single-vpc-design/

Pretty much every time that I try to SSH into a machine and it times out, it’s because I haven’t correctly set up the network ACL on the subnet.

Both incoming and outgoing?

I would check:- Applied SG on the instance. use the description of the instance and “view inbound rules”. This will show you what is being efectively applied, check that everything is correct.

- I suppose your instance has a public IP, and that your subnet has a route table that does route to internet via internet gateway, but double check it.

- You can view the console logs of the instance from AWS, just in case something is fishy.

- You can create a simple amazon linux machine on that subnet and SSH it to check that iptables or something inside the machine is not blocking the incoming connections. Also if you are able to enter this instance, try to copy the pem to that instance and try to SSH using the lan IP of the Kali.

- Use an online service to also check if the instance is reachable from outside, i don’t know if your corporate network may be blocking SSH or other protocols to non-trusted networks or something like that. This one will do the trick: https://www.yougetsignal.com/tools/open-ports/

If you want , send me a pic of your subnets ,route tables and routes for each route table

If you are getting a timeout it’s either security groups, network ACLs or the AMI itself. Try with Amazon Linux first, see if that works - maybe Kali has some special config.

Try recreating the instance. I’ve seen a few times that will fix it too.

  1. Check if ec2 can access internet inside vpc
  2. Check security group allow traffic from 0.0.0.0/0 to your ec2, inbound rule
  3. Check network access control list allow both inbound and outbound traffic, outbound means from security group to 0.0.0.0, inbound means from 0.0.0.0/0 to your security group
  4. Check subnet ENI has proper CIDR block, enough IPs
  5. Allow all traffic to verify connection quickly
  6. Update proper rule on security group once you are done

Pretty sure this AMI is broken. I attempted to ssh into a new instance in a known good VPC/subnet and it would refuse the connection every time. Ping works when included in the sg just no ssh.

Edit: same marketplace image, same region

Currently seeing how I might break into it, running the rescue automation. Will let you know the result.

You don’t have a public IP, so unless you connect to your VPC via VPN, it will always timeout.

Google “AWS Systems Manager EC2 Rescue”

I’m not the same user who’s trying it. Simply pointing you towards information on the Rescue service.