Cannot connect to EC2 server anymore:"Connection refused on port 22"

5,547

The error you are seeing is indicating that there is no service listening on TCP/22 on the host to which you are trying to connect. This indicates that either:

  • You are not connecting to the server you think you are,
  • The SSH daemon has died,
  • The host has shut down, or
  • Other failure mode, either transient (temporary routing or DNS problem) or catastrophic (the host has gone catatonic or is otherwise precluded from answering incoming SSH connection requests).
Share:
5,547

Related videos on Youtube

Linux Oracle User
Author by

Linux Oracle User

Updated on September 18, 2022

Comments

  • Linux Oracle User
    Linux Oracle User almost 2 years

    I have been able to successfully log into my ec2 2 times in the past. I srestarted the instance once and was successful in logging in. Now when I try to login, I get this error

    ssh -vvv -i "test.ppk" [email protected]
    OpenSSH_7.1p2, OpenSSL 1.0.1g 7 Apr 2014
    debug1: Reading configuration data /etc/ssh_config
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to ec2-11-162-345-000.compute-1.amazonaws.com [56.187.068.298] port 22.
    debug1: connect to address 56.187.068.298 port 22: Connection refused
    ssh: connect to host ec2-11-162-345-000.compute-1.amazonaws.com port 22: Connection refused
    

    The last thing I did was use winscp to copy files onto the ec2 server 2 days ago so that I could clone a database. That went along smoothly. Come 2 days later and I can't connect anymore. I am using MobaXterm.

    • Ketan Maheshwari
      Ketan Maheshwari about 7 years
      couple things to test would be to see if the vm is still running and if you can ping to it.
    • Silvio Silva
      Silvio Silva about 7 years
      Make sure you're using correct host name. The IP will be changed after restart unless you've attached elastic IP
    • Linux Oracle User
      Linux Oracle User about 7 years
      @Putnik yup, I did do that.
  • Linux Oracle User
    Linux Oracle User about 7 years
    The last option is on the only option as im able to ping to the server and it is the one im ssh'ing to. The daemon is running, and the host is up im 100% sure of. So somehow between now and 2 days ago, something happened that made the server refuse connections.
  • Pankaj Goyal
    Pankaj Goyal about 7 years
    "I can ping it but I am getting Connection refused when SSHing in" points firmly at option #2 of that list.
  • Linux Oracle User
    Linux Oracle User about 7 years
    It's up ps aux | grep ssh 13124 1 13124 13124 ? 1001 Jun 2 /usr/bin/ssh-pageant S 11832 1 16140 13884 pty0 1001 Jun 2 /usr/bin/_ssh S 11712 1 16372 12684 pty1 1001 Jun 2 /usr/bin/_ssh 16624 1 16624 16624 ? 1001 12:58:57 /usr/bin/sshd I'm able to connect to other servers. Just not this one which is an ec2.
  • KevinO
    KevinO about 7 years
    @LinuxOracleUser, how did you generate the ps on a host to which you cannot connect? Though probably less likely, you may also want to check/consider firewall status.
  • Linux Oracle User
    Linux Oracle User about 7 years
    @KevinO im using my local terminal. I guess this means i have to change something on the en2 server itself. Im still not sure how to do that if i cant get in.