ssh Connection refused: how to troubleshoot?

ssh
101,375

Solution 1

You don't have an SSH daemon running. If you look at the output from the ps ax command, you see that the only two processes with 'ssh' in the description are ssh-agent (which does something entirely different from sshd) and the grep ssh process that you're using to filter the output of ps.

Depending on what distribution installed, you may need to install or run the ssh server, usually called openssh-server or sshd depending on your package manager.

Solution 2

Steps for debugging the above problem:

  1. Use nmap tool to know which ports are open in that server. nmap is a port scanner. Since it may be possible that ssh server is running on a different port. nmap will give you a list of ports which are open.

     $ nmap myserver
    

2 . Now you can check which server is running on a given port. Suppose in the output of nmap, port 2424 is open. Now you can which server is running on 2424 by using nc(netcat) tool.

 $ nc -v -nn myserver portno

Suppose the output of 2424 port is:

myserver 2424 open
SSH-2.0-OpenSSH_5.5p1 Debian-4ubuntu5

This means ssh is running on 2424.

Keep on changing the portno in the above command and check for all the ports which are listed open by nmap.

Solution 3

That means either the ssh server isn't running on that machine or the firewall isn't allowing ssh through. You can check if ssh is running with 'ps -ax | grep ssh'.

Solution 4

The previous two options are good. You can also use the -v or -vv arguments.

$ ssh -vv eric@myserver
Share:
101,375
Eric Wilson
Author by

Eric Wilson

Updated on September 18, 2022

Comments

  • Eric Wilson
    Eric Wilson over 1 year

    I'm trying:

    $ ssh eric@myserver
    

    where myserver is a machine in the intranet. I can ping myserver or respond to HTTP on port 8080, etc, but when I try ssh, I get

    ssh: connect to host myserver port 22: Connection refused
    

    I'm using Ubuntu 10.

    ps -ax, as suggested gives:

    eric@Isaiah:~$ ps -ax | grep ssh
    Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
     1641 ?        Ss     0:04 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session gnome-session
    18376 pts/3    S+     0:00 grep --color=auto ssh
    
  • Eric Wilson
    Eric Wilson over 12 years
    Edited question to show results of ps -ax. Not sure what it means.
  • ChrisCornwall
    ChrisCornwall over 12 years
    It means ssh is not running.
  • Eric Wilson
    Eric Wilson over 12 years
    Weird. I'm not sure why you have twice now offered help that is not really helpful. First you suggest a command useful to check if ssh is running, without telling me how to interpret the results. Then you provide the minimal interpretation of those results, without a hint as to how you arrived at that interpretation, or what action might be appropriate. I'm not sure whether you are trying to help me, and are misjudging my level of experience, or if you are trying to highlight my ignorance.
  • ChrisCornwall
    ChrisCornwall over 12 years
    The list of processes does not include an sshd process, which means sshd is not running. The solution is to start sshd.