atack
atack

Reputation: 55

Unable to SSH into AWS EC2 Instance: Operation timed out

Please help! I've spent multiple days trying to ssh into my EC2 instance.

I'd been able to do this for the first 24 or so hours. Then as I was adding dependencies to my instance I got booted. Now I'm unable to get back in. At one point my Public DNS changed but I've accounted for this.

My security groups, VPCs, internet gateways, route tables, subnets, firewall, etc. seem to all be in order too.

What is the issue here? Please advise!

Upvotes: 0

Views: 2368

Answers (2)

jkimathi
jkimathi

Reputation: 1

I could neither SSH and my instance was reachable before. Apache also could not reach and it was reaching.

By chance when I changed elastic IP, everything worked.

Hope this helps.

Upvotes: 0

mon
mon

Reputation: 22366

Test connectivity to SSH

  1. Create another EC2 instance in the same subnet of the target EC2.
    • Make sure the egress rule allow all outbound, and inbound to port 22.
    • Copy the SSH private key to ~/.ssh/ and make sure to remove group/other rw permissions.
  2. Install telnet or nc if not installed in the new EC2.
  3. Test the connectivity to the target EC2 from the new EC2.
    telnet ${TARGET_HOST_IP} 22

If this works and you can connect, then SSH server is up and running. If not, SSH server is not running, or the port 22 is not open.

If somehow the SSH server is down, there could be some ways to try to fix.

See User is reporting that they've unable to SSH into an EC2 instance in AWS? for the options such as mount the root EBS volume to another EC2, or use USEDATA to reconfigure.

Login to EC2 from EC2 console

If you can login, then make sure SSH server is up and running. Then make sure ~/.ssh/authorized_key has the public key. Verify /var/log/auth or /var/log/security to verify if login gets denied if try to ssh into the EC2 from outside.

Clone to investigate or to replace

If you can, shut the EC2 instance, take a ELB snapshot of the root volume, then mount it to another EC2 you can SSH into, and investigate dmesg, /var/log files for any errors that may prevent SSH connections. Verify ssh server configuration, ~/.ssh/ files.

Or simply copy the contents you need from the ELB snapshot to a new EC2 instance and replace the original one with the new one.

AWS is clear that to create a snapshot of the root ELB volume, the instance needs to be shutdown. Otherwise the integrity of the snapshot is not assured.


Update

To restore the SSH public key or permission of the ~/.ssh folder, also see [User is reporting that they've unable to SSH into an EC2 instance in AWS?

Upvotes: 1

Related Questions