Saturday, September 16, 2017

EC2 Ssh Connection Refused

When ssh: connect to host ip_address port 22 Connection refused

Won’t able to talk my box????
Exactly when you see the error - “ssh: connect to host ip_address port 22: Connection refused” while connecting to your AWS EC2 Instance, you will go to AWS forum and other channels in order to way the solution of your problem, need to response several questions and several answers. But it's very difficult to find the actual problem.
In order to get clues what the problem is, we should provide as many details as possible about what we have tried and the results we are getting. Because there are hundreds of reason why a server or service might not be accessible, also connectivity is the toughest issue to diagnose, especially when you are running something critical on your box.
I've seen several topics on this matter, but none offers a solution to my problem when I faced the same.  I was not aware for what should I look at first. So I walk through from the very basics and investigated the following thing
Use of verbose while ssh
    $ ssh -v user@x.x.x.x
This won’t help me as I didn’t found any meaningful information except connection refused.
  • After that I look for my security groups, well they haven’t provide me any  hint for further steps.
  • Then I tried telnet at port 22 from my public and private network which was again a hard luck for me.
    $ telnet X.X.X.X 22
  • Tried creating AMI and building new instance of it.
  • I've mounted the EBS of a broken instance on a running instance, look for the file configuration of my ssh.
           $ cat /etc/ssh/sshd_config
and compare that with running instance.
  • Also check for the entries in /etc/fstab, but entries was all perfect as per knowledge.
  • Tried to start the instance from the broken instance, as usual again find the same error.
Coming to AWS UI console :-
  • Further moving over the AWS UI, under Action I find option to put user data

So below entry were made
ssh_enabled: True

  • I have gone through different option in UI , just went through the system logs

          And find that the issue is with swap, which is showing error while mounting.
  • So I stopped the broken instance and mount the broken ebs volume to the running one and comment the  swap entry from /etc/fstab
  • Finally I found that my instance is up and running, again I look for the system logs in aws UI, where login was prompt was able to access my instance again.

Conclusion :-
If you come across any such error then follow the AWS console of the machine & look for the issue and get to the core of the problem.

This Is The Newest Post

1 comments so far