How to Fix “Connection refused by port 22” on Ubuntu

How to Fix “Connection Refused By Port 22” on Ubuntu 22.04 LTS

Port 22 is used by SSH on Ubuntu for communicating with other machines in the network to transfer data. Port 22 is also used to access the remote system. Meanwhile, this post is for you if you are having the error “Connection refused by port 22” while using port 22. In this post, we will show you the solution for the “Connection refused by port 22” error on Ubuntu.

Before jumping into the solution, let’s have a look at the possible reasons for the “Connection refused by port 22” error on Ubuntu.

Reason For “Connection refused by port 22” error on Ubuntu.

  • The OpenSSH package is not installed on Ubuntu where you are trying to connect.
  • SSH server is not active

 

How to Fix “Connection refused by port 22” on Ubuntu

The most common reason behind this error is  OpenSSH has not being installed on Ubuntu where you are trying to connect.  To see whether OpenSSH is installed or not, run the following command on a remote machine.

sudo apt list --installed | grep openssh-server

If you see nothing printed out on the console, then you do not have it installed. You can easily install OpenSSH using the following command:

sudo apt install openssh-server -y

Now, the issue with port 22 should have been solved. Meanwhile, if you are still having issues then the SSH server might not be active. You can confirm the status of the service of SSH by using the following command:

sudo systemctl status ssh

Now, you can make it active with the following command

sudo systemctl start ssh
READ More Relevant Stuff:  How To Access Linux Files From Windows 11 [2023]
One thought on “How to Fix “Connection Refused By Port 22” On Ubuntu 22.04 LTS”
  1. I got the connection refused after rebooting on one machine but I was able to reconnect from another machine. Then, after connecting from the second machine, I was able to connect from the first.
    the openssh-server was installed and running. Weird situation, isn’t it?

Leave a Reply

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