Cannot ssh to localhost, Ubuntu 20.04

ssh localhost

ssh: connect to host localhost port 22: Connection refused

First you check the Firewall status, to see if ssh (port 22) is blocked.

sudo ufw status

The Firewall shows a status of inactive, so that can’t be the problem.  

Remember ssh requires a client and a server.  

Let’s check if the ssh server is running

Looks like there is only an ssh-agent running, which means no ssh server is running.

sudo systemctl status ssh

Ok, it’s installed….right?

Failed to start ssh.service: Unit ssh.service is masked.

Hmmm….. Okay.  There may have been a previous install of the ssh server, or there is a old or bad symlink left on our system.. Lets install open-ssh and see if that fixes our problem

sudo apt install openssh-server

Let’s start ssh and check the status of the service

sudo systemctl start ssh

sudo systemctl status ssh

I think we are finally ready to try to ssh to localhost again.

Great Success!!!

Leave a Reply

Your email address will not be published. Required fields are marked *