How to Install and Enable OpenSSH on Ubuntu 22.04

Secure SHell known as SSH is a secure communication protocol that connects (client and server) computers through the internet. It is a network protocol that transfers data between two computers over the network in a secure manner. OpenSSH is a tool used to log in remotely via SSH.

For building the connection, both computers (client & host) must have installed and enabled SSH. This write-up will illustrate the vast learning to install and enable OpenSSH on Ubuntu 22.04.

How to Install OpenSSH on Ubuntu 22.04?

OpenSSH server installation can be carried out from the default repository of Ubuntu 22.04. The following simple steps are performed to install OpenSSH on Ubuntu 22.04.

Step 1: Update System Packages

It is a good approach for updating the system repository for updated/latest packages. By considering it, execute the below script:

$ sudo apt update

All packages in the system are up to date.

Step 2: Install OpenSSH

To install OpenSSH on Ubuntu 22.04, run the command below:

$ sudo apt install openssh-server

The OpenSSH has been installed.

How to Enable and Configure OpenSSH on Ubuntu 22.04?

This section comprises several steps to enable and configure the SSH service on Ubuntu 22.04.

Step 1: Enable OpenSSH

Enable the SSH so that the SSH services will be enabled on every restart. To do so, run the below-mentioned command:

$ sudo systemctl enable --now ssh

The “OpenSSH” has been enabled.

Step 2: Check the Status of the OpenSSH Service

To check the OpenSSH services status, run the below-mentioned status command:

$ sudo systemctl status ssh

The status shows that SSH is active (running).

Step 3: Allow SSH on the Firewall

Your firewall may block incoming connections. Execute the below-mentioned command to allow the SSH connections on the firewall:

$ sudo ufw allow ssh

The output showed that the rule was updated.

To save all the changes, you should enable and reload the Firewall (ufw) by issuing the below-mentioned command:

$ sudo ufw enable && sudo ufw reload

How to Connect a Remote System (Machine) With the OpenSSH-server?

After installing and enabling SSH on Ubuntu 22.04, you can connect with any other system having OpenSSH. To continue the connection, use the username (host) and IP address in the following syntax:

$ ssh username@ip-address

Here, the username and IP address reflect the username and IP address of the machine you want to connect.

In our scenario, the following command will activate the session of the foss user, which is at IP-address 192.168.154.131:

$ ssh [email protected]

To continue with the connection, type “yes”, press the “Enter” key, and enter the “Password”.

How to Remove/Disable OpenSSH From Ubuntu 22.04?

If you want to remove/disable the OpenSSH from Ubuntu 22.04, run the provided command below:

$ sudo systemctl disable ssh --now

OpenSSH is disabled on Ubuntu 22.04.

Moreover, you can remove/uninstall the OpenSSH server using the below-mentioned command:

$ sudo apt remove openssh-server

The OpenSSH-server was successfully removed from Ubuntu 22.04.

Congratulations! you have learned the process of installing and enabling OpenSSH on Ubuntu 22.04.

Conclusion

OpenSSH is available on Ubuntu’s default repository and can be installed on Ubuntu 22.04 via the “sudo apt install openssh-server” command. OpenSSH uses the SSH protocol to connect with other machines remotely. This write-up has illustrated the method for installing and enabling OpenSSH on Ubuntu 22.04. We have also demonstrated the steps to connect to a remote machine via OpenSSH.