Skip to main content
Alemasone

Install and Configure SSH on Ubuntu: Complete Guide

Learn how to install, start and configure an OpenSSH server on Ubuntu. Follow our SEO-friendly guide for secure remote access to your server.

4 min read Updated on
Install and Configure SSH on Ubuntu: Complete Guide

SSH (acronym for Secure Shell) is the industry standard for secure remote access to Linux/Unix servers. This client-server protocol allows you to execute commands and manage remote files in total security. The demon responsible for this service is called SSHD and, by default, listens to TCP port 22 in operating systems like Ubuntu. Thanks to the powerful suite, system administrators can permanently abandon obsolete and insecure protocols such as rsh, telnet and ftp, ensuring end-to-end encrypted communications that are immune to network interceptions.

Prepare Ubuntu #

The very first operation to be performed before installing SSH on Ubuntu is updating the apt package list to the latest releases. This step guarantees stability and prevents software conflicts. Open the terminal and type the following command:

sudo apt update && sudo apt upgrade

Install SSH on Ubuntu #

As a rule, the OpenSSH server package is not preinstalled on the Desktop versions of the operating system. We then proceed with manual installation by typing in the terminal:

sudo apt install openssh-server

The system will start downloading and installing the necessary dependencies. Confirm by responding “Yes” (or “Y”) to various system prompts to conclude the process.

Start SSH #

Once the installation is completed, it is essential to enable and start the SSHD service in the background using the systemctl management tool:

sudo systemctl enable --now ssh

The addition of the --now key is an extremely useful shortcut: it immediately initiates the daemon and, at the same time, enables it to automatically start each system restart.

To ensure that the OpenSSH service is enabled and functions without errors, make a quick state verification:

sudo systemctl status ssh

If everything went well, the output will show the words Active: active (running). Press Q on the keyboard to exit the status screen.

If you have to stop remote access to the server for maintenance or security reasons, you can easily disable the service like this:

sudo systemctl disable ssh

This command disables the service and prevents it from automatically switching on the machine.

Configure firewall #

Before attempting any external connection via SSH, you must check that the machine firewall is configured to accept incoming requests. For detailed information on safety criteria, see official Ubuntu documentation on UFW.

In our case, we will use our own UFW (Uncomplicated Firewall), the Ubuntu standard. We carry out state control:

sudo ufw status

In the output generated, you should confirm that SSH traffic is allowed (ALLOW). If you do not see rules for port 22 or for OpenSSH profile, you must allow incoming connections by entering this instruction:

sudo ufw allow ssh

Connect to the server #

After configuring the daemon and firewall, your server is finally ready to receive connection requests from remote clients.

To establish the link, you will need three elements: protocol, server IP address (or domain name) and username (username) enabled access to the remote server.

From the terminal of your local computer, type the command respecting the following syntax:

ssh username@indirizzo_IP

Alternatively, if a valid web domain is associated with the server:

ssh username@dominio

FAQ – Frequently Asked Questions about SSH and Ubuntu #

1. What is the default door of SSH and why change it? #

The default port assigned to the SSH protocol is TCP 22. Many system administrators and devOps prefer to change it by acting on the /etc/ssh/sshd_config file. Changing port is a useful strategy to evade automated network scans and mitigate brute-force access attempts addressed to standard services.

2. What is the substantial difference between SSH and Telnet? #

The main difference is security. Telnet sends data packages (including username and password) in clear (plaintext), making them vulnerable to theft through packet sniffing. SSH, on the contrary, creates a virtual tunnel based on strong encryption, ensuring that no one can intercept or manipulate the traffic exchanged between client and server.

3. How can I increase the security of my OpenSSH server? #

To arm your Ubuntu server, it is highly recommended to disable direct access to the administrator user by modifying the PermitRootLogin no directive. Moreover, disable authentication by traditional password in favor of the use of a pair of SSH cryptographic keys (public/private) ensures that only authorized computers provided with the correct certificate can login.

Read next