I'm getting an error message when attempting to ssh into my ec2 instance after installing updates and rebooting: my connection gets refused. I'm wondering if the problem is related to some changes I made to /etc/fstab, where I added lines mounting directories in other places, changes I had also made to a local machine which caused it to boot up in emergency mode at one point.

When I run ssh -vvv -i path/to/pem.pem [email protected], I'm getting the following response (replaced actual IP address with 'w.x.y.z'):

OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "w.x.y.z.us-west-1.compute.amazonaws.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to w.x.y.z.us-west-1.compute.amazonaws.com [w.x.y.z] port 22.
debug1: connect to address w.x.y.z port 22: Connection refused
ssh: connect to host w.x.y.z.us-west-1.compute.amazonaws.com port 22: Connection refused
  • This indicates SSH is not running on the server. If it were AWS security groups blocking it, you would get a connection timeout, not connection refused. Nothing is listening on port 22.
    – jordanm
    Jan 29, 2018 at 20:53
  • @jordanm any idea why SSH may not be running? I tried restarting the instance in case the daemon had died but that didn't help.
    – Evan
    Jan 29, 2018 at 21:14
  • Not without being able to look at the server-side logs
    – jordanm
    Jan 29, 2018 at 21:16
  • I guess it did not boot properly. I am not familiar with AWS, but you need to run some kind of recovery mode. Jan 29, 2018 at 21:34

1 Answer 1

ssh: connect to host w.x.y.z.us-west-1.compute.amazonaws.com port 22: Connection refused

This is a response from the server itself so this shows that you have network access to your instance... so that leaves 2 scenarios.

  1. sshd failed to start on your server or
  2. You have a firewall that is explicitly rejecting connections to that port.

In either case, the best way to resolve this is to slave your instance and look at the logs. This means you have to launch another EC2 instance (the rescue instance) in the same Availability Zone as the broken one and then mount the root volume of the broken instance onto the rescue instance to troubleshoot. AWS has a detailed step-by-step guide on how to do this and you can find it here. Once you have access to the root volume of your broken instance, you want to first take a look at the system log file /var/log/messages and you will most likely find logs on why sshd failed to start (probably misconfigured sshd_config or something along those lines)... you will also get a chance to fix your firewall if your firewall is the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .