How to solve 'Connection refused' errors in SSH connection?
Solution 1:
You must install openssh-server on Linux before this will work. Get the internal IP address of Ubuntu and use that IP to setup port forwarding on port 22 (SSH) section of your router. Although if you don't intend to SSH from outside your network, this is not required.
Here's how to install openssh-server:
sudo apt-get install openssh-server openssh-client
[ENTER PASSWORD]
Solution 2:
IP address conflict turned out to be the root cause when I was seeing this SSH error message.
After reading the answers above I suspected an IP address conflict, but needed to prove that address conflict was or was not the problem.
This great article showed how to use arp-scan to see if two pieces of hardware were claiming the same IP address.
In my case the server machine had a static ip address of 192.168.1.42, I used arp-scan to check that address:
$ sudo apt-get install arp-scan
$ arp-scan -I eth0 -l | grep 192.168.1.42
192.168.1.42 d4:eb:9a:f2:11:a1 (Unknown)
192.168.1.42 f4:23:a4:38:b5:76 (Unknown) (DUP: 2)
Sure enough there was a conflict, as shown above. Then I ran arp-scan without the grep, found that .43 was available, went and edited /etc/network/interfaces
and changed the static ip from .42 to .43
Solution 3:
Use arping
on the IP address that is having connection issues. That will show the MAC address for each ping reply, and hopefully will unmask the rogue MAC address.
arping 192.168.2.254
You should check the DHCP IP address pool on the DHCP server, make sure no devices have static IPs that collide with the DHCP pool.
These clues point to duplicate IP:
- ping ttl and round trip time looks like 2 distinct servers
- intermittent disconnects without rebooting
Solution 4:
open the file of ssh config:
sudo nano /etc/ssh/ssh_config
find the port
#port 22
remove sharp the port option
then save the file by ctrl + x and restart your service
sudo service ssh restart