How to Enable OpenSSH Server on Ubuntu Linux- A Step-by-Step Guide
Table of contents
Ensuring secure and efficient remote access to servers is crucial for managing and maintaining systems. OpenSSH plays an important role in performing all of the above tasks. It ensures safe, effective remote access and encrypts the transmitted data, which helps protect sensitive information from being intercepted by malicious actors.
This guide will walk you through enabling the OpenSSH server on an Ubuntu Linux system. Whether you’re setting up a new server or configuring an existing one, you’ll learn how to install, configure, and verify the OpenSSH server to ensure secure and reliable remote access to your Ubuntu machine.
What is OpenSSH?
SSH stands for Secure shell. OpenSSH is a network protocol that allows you to connect to and manage computers remotely. It allows file transfer from your host computer to your remote computer and allows you to execute commands within a secure environment.
It is a remote management tool that allows you to run commands on another machine. OpenSSH was developed by the OpenBSD project. Due to its encrypted communication protocol, OpenSSH is one of the most secure network protocols for client-server architectures.
Steps
In this tutorial, I will be using Ubuntu 22.04 on WSL2
- Launch the Ubuntu terminal
Run the following commands to update your system
sudo apt update && sudo apt upgrade
After updating your system, enter the
clear
command to have a clear terminal.
- Check if OpenSSH is installed.
Run the following command to check if OpenSSH has already been installed. If installed, you will see the following output
sudo apt list -a openssh-server
If not installed, you can proceed with the following steps.
Install the OpenSSH server using the command below
sudo apt install openssh-server
Configure the firewall rules for OpenSSH.
But first, check the status using this command
sudo ufw status
If inactive, enable it using this command
sudo ufw enable
💡Ubuntu uses the Uncomplicated Firewall(UFW) to manage firewall rules.Next, allow inbound SSH connection by enabling a firewall rule with this command.
sudo ufw allow ssh
- Start and enable SSH service.
To start SSH, enter this command
sudo systemctl start ssh
To enable SSH, enter this command
sudo systemctl enable ssh
Check the server status.
After enabling SSH, you must ensure the server is actively running on your system. To check, enter the following command.
sudo systemctl status ssh
The image below shows SSH is running on my system
Open the SSH configuration file to complete the setup
On your terminal, run this command
sudo nano /etc/ssh/sshd_config
You can edit the config file to suit your taste.
Activate the port by deleting the # symbol. The default port is 22. You can also change the port number to your preferred number. Do the same for the ListenAddress 0.0.0.0 and Password authentication.
Restart and check the status of the SSH service using this command
sudo systemctl restart ssh && sudo systemctl status ssh
Connect and Configure network access.
The final step is to log in to your Ubuntu server via SSH using its IP address. To get the IP address of your machine, run this command
ip addr
Next, copy the IP address and run this command to establish the connection
ssh username@your_ubuntu_ipaddr
You will be asked if you are sure you want to continue connecting. Type yes
Congratulations! You have successfully enabled SSH. As you can see, it is a straightforward process.
Subscribe to my newsletter
Read articles from Etugbo Judith directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Etugbo Judith
Etugbo Judith
I'm a Technical writer passionate about breaking down complex concepts into clear, concise and engaging content.