ssh connection refused

I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:

sudo apt-get purge openssh-server
sudo apt-get install openssh-server

so now its working.


TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.

First of all double check your host name and/or IP address.

The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.

If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd

If you don't try starting sshd and/or checking whether it is configured to listen on port 22.

EDIT

The bits to focus on are:

:22 - port 22

LISTEN - there is a process running and expecting incoming connections on port 22

sshd - the name of the process.

If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.


SSH Connection refused because of the following reason-

  1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.

  2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.

  3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.

*Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.