Home Ubuntu How to install and enable OpenSSH on Ubuntu 22.04 LTS

How to install and enable OpenSSH on Ubuntu 22.04 LTS

by Karen
install and enable openssh on ubuntu

You can use various methods to connect to a remote system from your local machine. One of the most popular methods today used to connect to remote machines is Secure Shell (SSH). SSH came to replace the insecure rlogin and rsh that could send users’ passwords over a network ‘unencrypted.’ The daemon program responsible for running the SSH client is called OpenSSH.

The Ubuntu desktop and Ubuntu server minimal do not come with OpenSSH installed by default. However, you can easily install this utility from the command line. This post will provide a comprehensive guide on installing and enabling OpenSSH on Ubuntu 22.04.1 LTS.

Installing OpenSSH on Ubuntu

You will need access to the Terminal and root privileges for this particular step. Follow the steps below.

  1. Launch the Terminal from the applications menu or use the keyboard shortcut (Ctrl + Alt + T).
  2. Execute the commands below to update the system and install the OpenSSH daemon.
    sudo apt update
    sudo apt install openssh-server
    sudo apt install openssh-client
    You will notice that we are installing two packages with the commands above – openssh-server and openssh-client. What’s the difference between the two?

    openssh-server: This module enables your PC to listen for any incoming connection requests from other remote systems.

    openssh-client: This module enables your system to make connection requests to other remote systems.

    Although you can decide to install one of the packages depending on your needs, installing the two packages would be great if you find yourself in a situation where you want to establish or listen to connection requests.
  3. After completing the installation, execute the command below to verify that SSH is installed and running on your system.
    sudo systemctl status ssh
    ssh status

    SSH status

    From the image above, you can see that the SSH service is up and running. However, if its “inactive,” use the commands below to enable and start SSH.

    sudo systemctl enable ssh
    sudo systemctl start ssh

Configuring Firewall

Firewalls in computer systems monitor incoming and outgoing traffic against a set of rules. To enable your PC to connect to other machines over SSH, you need to enable the SSH service or port 22.

You can use the UFW (Uncomplicated FireWall) to configure the firewall on Ubuntu. To allow SSH connections, execute the command below.

sudo ufw allow ssh

After allowing SSH through the firewall, enable the firewall if it was not enabled before using the command below.

sudo ufw enable

Use the command below to check the firewall status.

sudo ufw status
enable ssh through firewall

Enable SSH through the firewall

Up to this point, you can now use your PC to connect to other remote machines via SSH.

Connect to Remote PC via SSH

Tip: The machine you are trying to connect to should also have SSH installed and running.

For this post, we will try to connect to a Linux Mint, which is also connected to my local network. Below is the syntax for establishing an SSH connection.

ssh [remote-system-username] [ip-address]e.g
ssh caren@192.168.1.43
connect to remote systems

Connect to remote systems

From the image above, you can see we have successfully established a connection to the remote system. You can also see that the terminal prompt has changed to the “remote username.”

Note: If you are connecting to a remote system for the first time, you will see the message below on your Terminal.

The authenticity of host '192.168.1.43 (192.168.1.43)' can't be established.
ECDSA key fingerprint is SHA256:i9Eh8Qg2zKHNyhV3iNG68wScjee6/D8WOsCxrXzyx4s.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type “Yes” to continue.

Disabling SSH on Ubuntu

To disable SSH on your system, execute the command below on your system.

sudo systemctl disable --now ssh

If you wish to re-enable it in the future, you will use the command below.

sudo systemctl enable --now ssh

Uninstall OpenSSH

To uninstall OpenSSH from your Ubuntu system, execute the commands below on your system.

sudo apt remove openssh-server
sudo apt remove openssh-client

Conclusion

This post has given you a step-by-step guide on installing and enabling OpenSSH on Ubuntu 22.04.1 LTS. It has also shown you how to connect to remote systems using SSH. Do you have any comments or suggestions regarding this post? Please let us know in the comments below.

You may also like

1 comment

Andrei January 16, 2023 - 3:53 AM

This was useful! Thanks a lot!

Reply

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.