Categories: Ubuntu

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

The ports on Ubuntu are used for communicating with different machines as well as different protocols, similarly, port 22 on Ubuntu is used by the SSH (Secure Shell) server which is the secure way to connect with other machines in the network to transfer data as well as to access the other machines. Most Ubuntu users have to suffer from an error while using the SSH of “Connection refused by port 22”, for which in this blog, different methods are discussed using which we can fix this error.

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

There are three most common reasons behind this error:

Problem 1: The package of the OpenSSH is not installed

The most common reason behind this error is that in most cases the OpenSSH has not been installed on the client machine to which you are trying to connect. For the verification of this OpenSSH package installed on the client machine, use the command in the client machine:

$ sudo apt list –installed | grep openssh-server

The output is showing the package is not installed, so we will install it using the command:

$ sudo apt install openssh-server -y

Now if the error is because of this issue, then it should be resolved.

Problem 2: SSH Server is not active

Another reason behind this error is that the service of the SSH server is not active, and we can confirm the status of the service of SSH by using the command:

$ sudo systemctl status ssh

To activate the service, we will again use the systemctl utility with its start option:

$ sudo systemctl start ssh

Now again check the status of the service:

$ sudo systemctl status ssh

Problem 3: Connection with the wrong port

Lastly, problem is that the ssh service is linked with some other port instead of port 22, to confirm this, we will use the command:

$ sudo netstat -ltnp | grep sshd

In our case, the port is set 22 which is default but if there is some other port showing then you will use the following port number, for example, if it is port 44, then we will use the command:

$ ssh -p [port_number] [username]@[ip_address]

Conclusion

Most Ubuntu users have to face the issue of “Connection refused by port 22” which is of different reasons discussed in this article. Not only the reasons but the solutions to resolve those problems to fix the error of “Connection refused by port 22” are being explained.

Ubuntu Server Admin

Recent Posts

🚀 Deploy Elastic Stack on Ubuntu VPS (5 Minute Quick-Start Guide)

Here’s the guide to deploy Elastic Stack on Ubuntu VPS, with secure access, HTTPS proxying,…

1 day ago

🚀 Deploy Nagios on Ubuntu VPS

This guide walks through deploying Nagios Core on an Ubuntu VPS, from system prep to…

1 day ago

Shoryuken Has a New Maintainer, and v7.0.0 Is Almost There

After a decade under Pablo Cantero's stewardship, Shoryuken has a new maintainer - me. I'm…

5 days ago

A better way to provision NVIDIA BlueField DPUs at scale with MAAS

MAAS 3.7 has been officially released and it includes a bunch of cool new features.…

2 weeks ago

Ruby Floats: When 2.6x Faster Is Actually Slower (and Then Faster Again)

Update: This article originally concluded that Eisel-Lemire wasn't worth it for Ruby. I was wrong.…

2 weeks ago

MicroCeph: why it’s the superior MinIO alternative (and how to use it)

Recently, the team at MinIO moved the open source project into maintenance mode and will…

2 weeks ago