How to fix “Connection from port 22 refused” on Ubuntu 22.04

The ports on Ubuntu are used for communication with different computers as well as with different protocols, likewise port 22 on Ubuntu is used by the SSH (Secure Shell) server, which is the secure way to connect to other computers on the network to exchange data to transfer and to access the other machines. Most of Ubuntu users must suffer from connection from port 22 refused error while using SSH for which in this blog we are going to discuss different methods we can use to fix this error.

How to Fix “Port 22 Connection Rejected” on Ubuntu

There are three most common reasons for this error:

Problem 1: OpenSSH package is not installed

The most common reason for this error is that in most cases OpenSSH has not been installed on the client machine you are trying to connect to. To verify this OpenSSH package installed on the client machine, use the command on the client machine:

$ sudo apt list –installed | grep openssh-server

The output shows that the package is not installed, so let’s install it with the command:

$ sudo suitable To install openssh-server -y

Now if the error is due to this issue then it should be fixed.

Problem 2: SSH server is not active

Another reason for this error is that the SSH server’s service is not active and we can confirm the status of the service from SSH with the following command:

$ sudo Systemctl status sh

To enable the service, we’ll use the systemctl utility again with its startup option:

$ sudo start systemctl sh

Now check the status of the service again:

$ sudo Systemctl status sh

Problem 3: Connection to wrong port

Finally, the problem is that the ssh service is connected to a different port instead of port 22. To confirm this we use the following command:

$ sudo net stat -ltnp | grep sshd

In our case, the port is set to 22, which is the default, but if a different port is shown, use the following port number. For example, if it is port 44, we use the command:

$ sh – p [port_number] [username]@[ip_address]

Conclusion

Most Ubuntu users have to face the connection from port 22 refused issue which is discussed in this article for various reasons. Not only the reasons but also the solutions to fix these issues are explained to fix the connection from port 22 refused error.

Related Posts