Custom Search

Ubuntu ssh connection refused

Ubuntu ssh connection refused can be caused by several factors. This is a guide for Ubuntu ssh connection refused troubleshooting.

1) Check whether ssh is installed in your system using dpkg tool.

luzar@ubuntu:~$ dpkg -l | grep ssh
ii openssh-blacklist 0.1-1ubuntu0.8.04.1 list of blacklisted OpenSSH RSA and DSA keys
ii openssh-client 1:4.7p1-8ubuntu1.2 secure shell client, an rlogin/rsh/rcp repla
ii openssh-server 1:4.7p1-8ubuntu1.2 secure shell server, an rshd replacement

2) Check ssh daemon is running in your server with ps command.

luzar@ubuntu:~$ ps aux | grep sshd
root 4191 0.0 0.1 5316 1016 ? Ss Nov05 0:00 /usr/sbin/sshd
root 4608 0.0 0.7 11356 3728 ? Ss Nov05 0:00 sshd: luzar [priv]
luzar 4610 0.0 0.3 11512 2036 ? S Nov05 0:02 sshd: luzar@pts/0
luzar 14146 0.0 0.1 3008 776 pts/0 S+ 04:14 0:00 grep sshd

3) Make sure firewall is not blocking ssh. This is a default Ubuntu iptables with no rules configured.

luzar@ubuntu:~$ sudo iptables -L
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destination
Chain OUTPUT (policy ACCEPT)target prot opt source destination

4) Use netstat command to check that ssh is listening on port 22.

luzar@ubuntu:~$ sudo netstat -nap | grep :22
[sudo] password for luzar:
tcp6 0 0 :::22 :::* LISTEN 4191/sshd
tcp6 0 52 ESTABLISHED 4608/sshd:luzar [p


  1. I have tried all of your suggestions for troubleshooting, however none of these seems to be the issue... is there anything else that might cause the connection to be refused? I can ssh into the box just fine, however I cannot SCP into it. Thoughts? Thanks in advance!

  2. If you successfully ssh into the server, scp should be ok too. Try scp again and make sure username account, ip address and password are correct. Also make sure that scp command is correct.

  3. Hi, I am trying to setup ssh on this old linux box that I have and I have root access.
    I was having problem with my ssh and
    Somehow I decided that it is easier to reinstall openssh-server with apt-get.
    However, after reinstalling.. I get this weird error message

    Can you tell me the correct solution to this?
    Thanks alot

    desktop:/home/mini# ssh -l mini localhost
    Someone could be eavesdropping on you right now (man-in-the-middle attack)!
    It is also possible that the RSA host key has just been changed.
    The fingerprint for the RSA key sent by the remote host is
    Please contact your system administrator.
    Add correct host key in /root/.ssh/known_hosts to get rid of this message.
    Offending key in /root/.ssh/known_hosts:1
    RSA host key for localhost has changed and you have requested strict checking.
    Host key verification failed.

  4. you need to delete the entry for the host name and/or ip address in the ~/.ssh/known_hosts file and let them sync up again by connecting with ssh once before you try scp. The system is trying to do a key exchange and the key on the destination machine is different than the one in known_hosts.

  5. based on this is it listening or no? and how do I make it listen?

    scb@scb-Aspire-5250:~$ sudo netstat -nap | grep :22
    tcp 0 0* LISTEN 628/sshd
    tcp 0 0 ESTABLISHED 1982/skype
    tcp6 0 0 :::22 :::* LISTEN 628/sshd

  6. The list of 1 - 4 is not correct. If the package contqining ssh is not installed, then you will get "command not found" instead of "connection refused". And what else other than sshd is ever listening on port 22? If tests 2 and 4 do not fail or pass together, there is something seriously whacked about the system. Or somebody has changed the default configuration, in which case the user should know about it.

  7. @xvstephen I know this is a long time after your post, so it might not help you; but I hope my answer will be helpful to others as they find this. If you are running sshd with the default configuration (and why ever change it?), then it will be listening on port 22. Unless your version of sshd is seriously buggy, it should listen forever. You could start and stop the sshd server (or restart it), after which you should immediately find it listening. If that works, but the listening state on port 22 goes away (check this from inside the firewall), then you know you have a buggy implementation of sshd. But as long as you installed from an uptodate repository, this should never happen.

  8. This is long after the original post, however I'm getting a very strange problem with my ssh installation. If I try to ssh to my ubuntu machine from inside my private network (192.168...), i get the 'connection refused'. If, however, I ssh to it via my external address (forwarded through my router), it works just fine.
    Note that in both cases, I am originating at the same machine. If i ssh to, the connection is refused. If i ssh to (obviously made up, but you get the idea), it is forwarded to my linux machine and i connect fine. any ideas?


Please keep comment relevant and strictly no spam will be tolerated. Thank you.