Fix a “ssh: connect to host localhost port 22: Connection refused” error in Ubuntu

I was trying to install hadoop today and part of the setup was being able to ssh to localhost.

So I tried ssh localhost

ssh: connect to host localhost port 22: Connection refused

So googled around a bit; ssh was up and running no problem there.

I tried re-installing it, still no luck.

Came across this http://stackoverflow.com/a/25699125 

Checked which port sshd was listening on sudo netstat -tulpen

And what do you know, the port for sshd was not 22

I tried ssh to the said port:

ssh localhost -p 12345

and it worked!

Now I needed to change it:

Use your favorite editor to edit the sshd_config file

sudo nano /etc/ssh/sshd_config

Look for something like

# What ports, IPs and protocols we listen for
Port 12345

And change that port from 12345 to 22

Restart and you’re good to go!

sudo restart ssh