How to Enable SSH on Ubuntu 22.04

Secure Shell (SSH) is an open-source tool for transferring data to other operating systems. SSH protocol encrypt and secure your data with Two Factor Authentication. For authentication purposes, the SSH 8.2 version added a U2F/FIDO security key for extra security features. Thus, SSH is a more powerful and secure controlling tool to communicate between server and client.

The article will improve your skills on the following:

  • How to enable SSH on Ubuntu 22.04
  • How to disable and remove SSH from Ubuntu 22.04

How to enable SSH on Ubuntu 22.04

SSH provides a secure method of transferring data between server and client. You can be connected with other operating systems remotely by using SSH services. Ubuntu 22.04 provides facilities to enable SSH from your terminal. While transferring data, SSH uses the RSA algorithm for encryption.

The following steps refer to the install and enable SSH services on Ubuntu 22.04.

Step 1: Update system cache

Before you run any command in Linux/Ubuntu, update your system cache with the code:

$ sudo apt update

Step 2: Installation of server/client application

Run the command to check the status whether the SSH is installed or not.

$ sudo systemctl status ssh

Install Server and/or Client Applications with the help of single liner code.

For example, install a Server application, run the following command in your terminal and type ‘y’ to continue.

$ sudo apt install openssh-server

Also, Run the following command for the Client application.

$ sudo apt install openssh-client

Step 3: Enabling SSH

To enable SSH utility and service manager, run the command from your terminal.

$ sudo systemctl enable ssh --now

Now examine the SSH status and you will find ssh.service is active and running properly.

$ sudo systemctl status ssh

Step 4: Firewall configuration

In Ubuntu 22.04, UFW is a tool to configure the firewall. The following commands will enable and allow firewall on port 22:

$ sudo ufw enable

You will see the above message that Firewall is active and enabled on system startup.

Allow firewall at port 22 via the below-mentioned command:

$ sudo ufw allow 22

Reload the firewall to update changes with reload command.

$ sudo ufw reload

Your system Firewall is reloaded, successfully.

Step 5: Generating SSH keygen

The SSH keygen stage is very important. You cannot securely pair other machines without keys Thus, make sure that you have successfully generated the ‘rsa’ key.

$ ssh-keygen -t rsa

Run the above command and press Enter to generate a public/private security key.

Step 6: Connect with another machine

After generating SSH keygen, now it’s time to connect your system with other machines or operating systems through your system IP address. You can check your system IP using the command:

$ ip a

Step 7: Connecting SSH server

Finally, you have configured the prerequisites. Now just follow the syntax to connect with other systems.

$ ssh userName@IpAddress

The above syntax can be used to connect a specific user on a specific machine. For the specific user, you need to add the name of that user and the IP address refers to the machine.

By executing the following command, your system will be connected to the user named “zahid” on machine with IP address “

In my case, the IP address against zahid (userName) is (IpAddress).

$ ssh [email protected]

You will notice that the text in green is changed from itslinux@foss to (base)zahid@zahid-… with the message Welcome to Ubuntu 22.04 LTS.

Congratulations! You have connected two different systems successfully to share data.

Step 8: logout/exit

The exit command will log you out from the remote system.

$ exit

The output of the above exit command will return the logout message.

How to disable and remove SSH from Ubuntu 22.04

In case, you do not need SSH then you can either disable the SSH or remove it from Ubuntu 22.04. We have provided the commands to remove and disable SSH on Ubuntu 22.04.

Step 1: Stop SSH service

It is a good practice to Stop your service before removing the packages. To Stop SSH services on your system run the following command.

$ sudo service ssh stop	

The above image demonstrates that the service has been stopped successfully.

Step 2: Remove Configuration Files

Now, it’s time to remove all the binaries and configuration associated with the SSH server. From your terminal run the command below:

$ sudo apt purge openssh-server	

Removing all packages can be seen during the Deletingprocess.

Note: You can use apt remove or apt purge, but keep in mind that apt remove will remove only binaries while apt purge will remove the package configuration files as well.


By using Ubuntu 22.04 official repository, you can install and enable SSH service. SSH service can be installed for both server and client applications. This article provides an overview about Installation and enabling SSH services with practical examples. SSH is a more powerful and secure controlling tool to communicate between server and client. We have also provided a way to connect two machines via the SSH service.