How to Install/Enable SSH on Ubuntu 22.04 LTS

SSH or known by its full name Secure Shell Protocol is a cryptographic network communication protocol that enables two computers to communicate securely over an unsecured network. SSH is highly used for remote login applications and command-line executables such as terminal applications.

For users wishing to connect to servers or other computers with SSH, the client and the remote connection need to both have SSH installed and enabled for this to be possible.

In the following tutorial, you will learn how to install and enable SSH on Ubuntu 22.04 LTS Jammy Jellyfish Desktop or Server and connect to a remote PC using the command line terminal.

Update Ubuntu

Before you begin, update your system to ensure no conflicts occur during the installation and enablement of SSH on your Ubuntu system.

sudo apt update && sudo apt upgrade -y

Install SSH (OpenSSH)

SSH is not installed or enabled on your Ubuntu 22.04 LTS system.

First, run the following command in your terminal to begin the installation.

sudo apt install openssh-server -y

Once installed, enable SSH using the following command.

sudo systemctl enable --now ssh

Next, check the status of the SSH instance to make sure it is running and no errors have occurred.

sudo systemctl status ssh

Example output:

Install/Enable & Connect to SSH on Ubuntu 22.04 LTS

Another handy trick is to use the following command to see open connections.

sudo ss -lt

Example output:

Install/Enable & Connect to SSH on Ubuntu 22.04 LTS

Configure UFW Firewall

Before attempting any connections, if you have UFW firewall enabled, you need to allow for port 22 using the following command.

sudo ufw allow 22/tcp 

UFW is installed by default; to enable it use the following command for those that do not have it enabled.

sudo ufw enable

Connecting to SSH Server

With SSH now installed and enabled, you can connect to a remote system, another remote PC, or a server. Remember, the SSH software must be enabled on both ends for this to work.

First, you will need to have the internal/external IP address or the hostname and preferably the username of the account connecting to, then use the ssh command to begin the connection.

ssh username@ip-address/hostname

When you connect to the remote SSH instance for the first time, you will receive the following message.


Install/Enable & Connect to SSH on Ubuntu 22.04 LTS

Type YES, then you will be prompted to enter your password; once done, press the ENTER KEY.

Example output (Connecting to Fedora 35 Remote PC):

Install/Enable & Connect to SSH on Ubuntu 22.04 LTS

As above, you have entered your password and successfully connected as instead of joshua@ubuntu, we now see joshua@fedora-35 since your terminal window is logged in to the remote session.

Do note you will see when the last login was and failed attempts demonstrated above. If you see lots of these, it means brute-force attacks are occurring, and you should look at stricter firewall rules or use something like fail2ban.

How to Disable SSH (OpenSSH)

For instances where you do not need SSH running, you should always have this disabled for security purposes. Many malicious bots scan the internet for SSH instances and brute force them if they are not secure.

To disable SSH, use the following command.

sudo systemctl disable ssh --now

When you need to have SSH re-enabled, use the following command.

sudo systemctl enable ssh --now

Alternatively, to remove SSH, remove it using the following command.

sudo apt autoremove openssh-server -y

Make sure to block port 22, do not forget this if you plan never to use SSH again on the system you are using.

sudo ufw deny 22/tcp 

Comments and Conclusion

In the tutorial, you have learned how to install and enable SSH (OpenSSH) on Ubuntu 22.04 LTS.

Overall, SSH is the go-to protocol compared to using other similar services such as TELNET which is not secure. However, ensure your firewalls are activated when using SSH over an open-unsecured network.

Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!