Jun 28, 2023 5 min read

How to Install and Enable SSH on Ubuntu 22.04

Install and enable SSH on Ubuntu 22.04 with our step-by-step tutorial. SSH allows secure remote access to computers and secure data transfer.

Install and Enable SSH on Ubuntu 22.04
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install and enable SSH on Ubuntu 22.04, let's briefly understand – What is SSH?

Secure Shell (SSH) is a secure network protocol that allows secure remote access to computers and secure data transfer. It provides a safe and encrypted connection between two devices, ensuring confidentiality and integrity of the data transmitted. SSH is widely used in system administration and remote management tasks, as well as for secure file transfers.

Its strong authentication and encryption make it a reliable choice for protecting sensitive information and preventing unauthorized access. With SSH, users can securely access remote servers, execute commands, transfer files, and manage network devices, all while keeping data safe from prying eyes.

This tutorial will show you how to enable SSH on Ubuntu 22.04. We will also address a few FAQs on how to install and enable SSH on Ubuntu 22.04.

Advantages of SSH

  1. Secure remote access: SSH enables secure and encrypted remote access to computers, allowing users to manage systems from anywhere.
  2. Strong encryption: SSH uses robust encryption algorithms to protect data during transmission, ensuring confidentiality and integrity.
  3. Authentication: SSH provides strong authentication mechanisms, preventing unauthorized access to remote systems.
  4. Secure file transfers: SSH allows for secure file transfers between devices, ensuring the privacy of sensitive data.
  5. Versatility: SSH is widely supported and used across various platforms and operating systems, making it a versatile and reliable choice for secure remote management tasks.

Enabling SSH on Ubuntu 22.04

When Ubuntu is first installed, remote access through SSH is disabled by default. On Ubuntu, enabling SSH is a simple process.

To install and enable SSH on your Ubuntu system, run the following commands as root or as a user with sudo privileges:

  1. Install the openssh-server package by pressing Ctrl+Alt+T in the terminal:
sudo apt update
sudo apt install openssh-server

To continue with the installation, enter your password when requested and press Enter.

2. The SSH service will start immediately after the installation is complete. You may check if SSH is up and running by typing:

sudo systemctl status ssh

The output should show that the service is up and running and that it is set to start automatically when the system boots up:

Output

● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Mon 2020-06-01 12:34:00 CEST; 9h ago
...

To return to the command line prompt, press q.

3. UFW, Ubuntu's firewall configuration tool, comes preinstalled. If your system has a firewall, make sure that the SSH port is open:

sudo ufw allow ssh

You can now use SSH to connect to your Ubuntu system from any distant computer. SSH clients are installed by default on Linux and macOS systems. Use an SSH client like PuTTY to connect from a Windows system.

Connect to the SSH Server

To connect to your Ubuntu machine over LAN, use the ssh command with the username and IP address formatted as follows:

ssh username@ip_address
💡
Make sure to replace username with the real user name and ip_address with the IP address of the Ubuntu computer where SSH was installed.

If you don't know your IP address, the ip command can help you figure it out:

ip a

The system IP address is 10.0.2.15, as seen in the output.

Once you've found the IP address, use the ssh command to connect to the remote machine:

ssh [email protected]

When you initially connect, you'll receive a notice similar to this:

Output

The authenticity of host '10.0.2.15 (10.0.2.15)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

If you choose yes, you'll be asked to enter your password.

Warning: Permanently added '10.0.2.15' (ECDSA) to the list of known hosts.
[email protected]'s password:

You'll be greeted with the typical Ubuntu message after entering the password:

Output

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-26-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
...

You've successfully signed onto your Ubuntu machine.

Connecting to SSH behind NAT

To access your home Ubuntu machine over the Internet, you'll need to know your public IP address and set up your router to receive data on port 22 and transfer it to the Ubuntu system running SSH.

Simply go to https://api.ipify.org to find out the public IP address of the machine you're attempting to SSH to, or use

curl ifconfig.me

When it comes to port forwarding, each router has its own method of doing so. For instructions on how to set up port forwarding, visit your router's documentation. In short, you must provide the port number on which requests will be made (the default SSH port is 22) as well as the private IP address of the computer where SSH is running that you discovered earlier (using the ip a command).

Once you've found the IP address and configured your router, you can log in by typing the following command.

ssh username@public_ip_address

It's a good idea to put some security measures in place if you're going to expose your system to the Internet. The simplest method is to set up your router to accept SSH traffic on a non-standard port and forward it to port 22 on the SSH server.

You can also log in to your Ubuntu machine without entering a password by using SSH key-based authentication.

Disabling SSH on Ubuntu

Stopping the SSH service on your Ubuntu system will disable the SSH server.

sudo systemctl disable --now ssh

To re-enable it later, type:

sudo systemctl enable --now ssh

FAQs to Install and Enable SSH on Ubuntu 22.04

How do I check if SSH is installed on Ubuntu 22.04?

Open the terminal and type ssh -V. If SSH is installed, it will display the version number.

How do I start the SSH service on Ubuntu 22.04?

SSH service starts automatically after installation. If it's not running, use sudo systemctl start ssh to start it.

How do I configure SSH on Ubuntu 22.04?

SSH configuration is done in the /etc/ssh/sshd_config file. Edit this file using a text editor like nano or vim.

How do I allow SSH access for a specific user on Ubuntu 22.04?

Add the user to the AllowUsers line in the /etc/ssh/sshd_config file. Save the changes and restart the SSH service.

How do I connect to an SSH server on Ubuntu 22.04?

From another device, open a terminal and use the command ssh username@server_ip_address to connect to the SSH server.

Can I change the default SSH port on Ubuntu 22.04?

Yes, you can change the default port in the /etc/ssh/sshd_config file by modifying the Port line. Remember to restart the SSH service.

How do I disable SSH on Ubuntu 22.04?

To disable SSH temporarily, use sudo systemctl stop ssh. To disable it permanently, run sudo systemctl disable ssh.

Conclusion

On Ubuntu 22.04, we've shown you how to install and enable SSH. You may now use the command prompt to log into your system and execute common administrative chores.

If you manage several systems, defining all of your connections in the SSH config file can help you streamline your workflow. By minimizing the danger of automated attacks, changing the default SSH port gives an extra layer of security to your system.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.