how to enable ssh on ubuntu 20.04

admin3 April 2024Last Update :

Introduction to Secure Shell (SSH) on Ubuntu 20.04

how to enable ssh on ubuntu 20.04

Welcome to the comprehensive guide on enabling SSH on Ubuntu 20.04, a crucial skill for any system administrator or developer working with Linux servers. SSH, or Secure Shell, is an encrypted network protocol that allows for secure remote login from one computer to another. It provides a secure channel over an unsecured network, making it a standard method for remotely managing systems and applications. In this article, we will delve into the steps required to set up and enable SSH on Ubuntu 20.04, ensuring you can connect to your server securely and efficiently.

Understanding SSH and Its Importance

Before we jump into the technicalities of enabling SSH, let’s understand why SSH is so important in today’s digital landscape. With cyber threats on the rise, securing communication channels has become paramount. SSH offers encryption that safeguards data from eavesdropping and man-in-the-middle attacks, making it an essential tool for anyone who needs to perform tasks on a server remotely.

Prerequisites for Enabling SSH on Ubuntu 20.04

To get started with enabling SSH on Ubuntu 20.04, you’ll need the following:

  • A machine running Ubuntu 20.04
  • Sudo privileges or access to the root user account
  • An internet connection to download necessary packages
  • Basic knowledge of the command line interface (CLI)

Step-by-Step Guide to Enabling SSH on Ubuntu 20.04

Step 1: Installing the OpenSSH Server Package

The first step in enabling SSH on your Ubuntu system is to install the OpenSSH server software. This package contains the necessary tools to create an SSH server on your machine.

sudo apt update
sudo apt install openssh-server

After installation, the SSH service will start automatically. You can verify that the service is running by using the following command:

sudo systemctl status ssh

Step 2: Configuring the SSH Server (sshd_config)

Once the OpenSSH server is installed, you may want to configure it to enhance security or change default options. The configuration file for the SSH server is located at /etc/ssh/sshd_config. Use a text editor like nano or vim to edit this file:

sudo nano /etc/ssh/sshd_config

Here are some common configurations you might consider:

  • Changing the default SSH port (Port 22) to a custom one for added security
  • Disabling root login over SSH (PermitRootLogin no)
  • Allowing only specific users to log in via SSH (AllowUsers username)

Remember to restart the SSH service after making changes to the configuration file:

sudo systemctl restart ssh

Step 3: Adjusting the Firewall Settings

Ubuntu comes with a built-in firewall called UFW (Uncomplicated Firewall). If UFW is enabled, you’ll need to allow SSH connections through the firewall:

sudo ufw allow ssh

Or, if you’ve changed the default SSH port, replace ‘ssh’ with the new port number:

sudo ufw allow [custom_port]/tcp

Then, enable the firewall if it’s not already active:

sudo ufw enable

Step 4: Connecting to Your Ubuntu System via SSH

With SSH enabled and configured, you can now connect to your Ubuntu system from another computer. On a client machine, use the following command to initiate an SSH connection:

ssh [username]@[server-ip-address]

Replace ‘[username]’ with the actual user account on the Ubuntu system and ‘[server-ip-address]’ with the server’s IP address. If you’re using a custom port, add ‘-p [custom_port]’ to the command.

Enhancing Security for SSH Connections

Using Key-Based Authentication

Password-based authentication is vulnerable to brute-force attacks. A more secure alternative is key-based authentication, which uses a pair of cryptographic keys for authentication.

Disabling Password Authentication

To further secure your SSH server, consider disabling password authentication entirely once key-based authentication is set up. This can be done by editing the /etc/ssh/sshd_config file and setting ‘PasswordAuthentication’ to ‘no’.

Implementing Fail2Ban

Fail2Ban is an intrusion prevention software that protects your server against brute-force attacks. It monitors log files and bans IP addresses that show malicious signs.

FAQ Section

How do I change the SSH port on Ubuntu 20.04?

Edit the /etc/ssh/sshd_config file and change the ‘Port’ directive to your desired port number. Restart the SSH service afterward.

Can I use SSH without a password?

Yes, by setting up key-based authentication, you can use SSH without entering a password each time.

Is it safe to disable the root login over SSH?

It is generally recommended to disable root login over SSH to prevent unauthorized access to your server. Instead, use a non-root user with sudo privileges.


Enabling SSH on Ubuntu 20.04 is a straightforward process that significantly enhances your ability to manage your server remotely and securely. By following the steps outlined in this guide, you can ensure that your SSH server is properly set up and configured for both convenience and security. Remember to stay vigilant about server security and regularly update your practices as new threats emerge.


For further reading and advanced configurations, please refer to the official Ubuntu documentation and OpenSSH manuals available online.

Leave a Comment

Your email address will not be published. Required fields are marked *

Comments Rules :

Breaking News