0

I had created an Amazon EC2 instance and was able to SSH into it previously. Now if I try to SSH into it, I get the error as below:

ssh: connect to host [ip address] port 22: Connection timed out

I've not changed anything in the security group and NACL to which the instance and the subnet are attached respectively.

Creating another instance from the AMI of this instance doesn't seem to work either.

I tried fixing the problem by detaching the EBS volume from this instance and mounting it to a fresh instance for checking /etc/ssh/sshd_config, but there wasn't any problem there.

I've also tried commenting out stuff from the fstab as per the solution https://stackoverflow.com/a/14050894

I'm facing the same issue in around 3 instances, kindly help.

Below is the output of ssh -v

OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ip [ip] port 22.
debug1: connect to address ip port 22: Connection timed out
ssh: connect to host ip port 22: Connection timed out
  • A timeout indicates that no network connection was established. Triple-check your **Security Group** configuration. You might be connecting from a different IP address. This is rarely a problem with the instance itself. – John Rotenstein Nov 18 '19 at 09:22
  • I've already allowed All Traffic for All Sources, still no luck. – Anchal Chaudhary Nov 18 '19 at 09:57
  • I would suggest launching a new Amazon Linux instance in the same subnet and trying to connect. This way, you'll be testing the connectivity rather than the instance. Connect via `ssh -i key.pem ec2-user@IP-ADDRESS` – John Rotenstein Nov 18 '19 at 10:09
  • I do have 2 other instances running in the same subnet and I'm able to SSH into them properly. – Anchal Chaudhary Nov 18 '19 at 10:34
  • If those other instances have the same Security Group, then it is strange that the instances are giving a Timeout since they would have the same network access. – John Rotenstein Nov 18 '19 at 10:42
  • Tried changing Security Groups and adding necessary rules too, doesn't work still. – Anchal Chaudhary Nov 18 '19 at 10:51

1 Answers1

0

After much struggle, I've resolved this issue by mounting the volume of the instance I was unable to SSH into with another EC2 instance created using the same key, and thereafter replacing the .ssh/authorized_keys file in the attached volume with .ssh/authorized_keys in the newly created instance. Finally, reattaching this volume to the original instance. There wasn't any difference between the two authorized_keys files, so I can't say why did replacing the file work. Creating a new instance with the AMI of the problematic instance using a new key should've worked which didn't for some reason unidentified as of yet.