Have you tried to connect to an Ubuntu server via ssh and received a “ssh: Connecting to host port 22: Connection refused” error? This may be because you need to enable SSH on your Ubuntu server.
Please follow the steps below to fix the “Host Port 22: Connection refused” error by enabling SSH on your Ubuntu Linux server.
The steps described in this guide are for Ubuntu 22.04.3. If your server is a different version, I can’t guarantee it will work.
Step 1: Install OpenSSH server
You need a tool to handle ssh requests to the server. OpenSSH Server allows you to remotely ssh to your server.
The first step to enable ssh on Ubuntu is to install the OpenSSH server.
Please follow the steps below to install.
- Update Ubuntu Application Manager by executing the following command:
sudo apt-get update
You will be prompted for the root password.
- After that, install the OpenSSH server by executing the following command:
sudo apt-get install openssh-server
Step 2: Allow SSH port on Ubuntu server(22)
After installing the SSH server, the final step to enable SSH on the server is to allow port 22.
Proceed as follows:
- Check the firewall status on the Ubuntu server by executing the following command:
sudo ufw status
The command should display “Status: Inactive”.
- Enable firewall on Ubuntu server:
sudo ufw enable
The above command should return “Firewall is active and enabled on system startup.”
- Enable SSH for all incoming requests on the default port (22) with the following command:
sudo ufw allow ssh
With this command, you have completed the steps to enable SSH on Ubuntu 22.04.3!
Afterwards, to connect to the server via ssh, execute the following command:
sudo user@servername
Change “user” to your username and “servername” to the hostname or IP address of your Ubuntu server.
now it’s right! Allowing SSH in Ubuntu is easy with just a few steps. Please tell us what you think using the comments form at the end of this page.
Other useful resources
- Why am I getting a “Port 22: Connection refused” error?
- How to enable ssh port 22 on Ubuntu 20.04 Focal Fossa Linux
- How to add SSH key to authorized_keys file?
3 Comments
Pingback: How to enable SSH in Ubuntu 22.04.3 – Tech Empire Solutions
Pingback: How to enable SSH in Ubuntu 22.04.3 – Paxton Willson
Pingback: How to enable SSH in Ubuntu 22.04.3 – Mary Ashley