monovm

Follow MonoVM
on social networks
and stay updated
with our new posts.

instagram twitter linkedin Youtube facebook telegram
English
+370 5 205 5502 sales@monovm.com

Step-by-Step Guide: How to Install and Enable SSH on Ubuntu

Learn how to securely access your Ubuntu system remotely by installing and enabling SSH. Our step-by-step guide walks you through the process, from installation to configuration. Increase your productivity and troubleshoot your Ubuntu system with ease.

26 Jan, 23 by Susith Nonis 7 min Read

List of content you will read in this article:

To securely connect a client to a server, the foremost concern is ensuring security. This is particularly true for Linux users. SSH is known as Secure Shell and is the default method for this purpose. This protocol allows them to access and manage a remote server from any location powerfully and efficiently. Are you planning to use SSH right now? Follow this article to learn how to enable SSH on Ubuntu and disable it when you don`t need it. But before we get started, let`s see what exactly SSH is.

SSH is a popular and free network protocol that establishes communication between two systems far apart. In addition to encrypting all traffic, SSH offers different authentication methods and configuration options to prevent hijacking and eavesdropping attacks. SSH encrypts every piece of data to ensure that no sensitive information is compromised during the process. So, as a client-server, you can safely transfer sensitive information, run command lines, and use any other network services.

These functions are typically accomplished via insecure tools, including Telnet and RCP, but they transmit users' passwords in cleartext. That’s why OpenSSH is recommended for server and client purposes. 

Before you start to do the instructions to install and enable SSH on the Ubuntu system, you need to be aware of the prerequisites mentioned below:

  • Permission to access the remote computer.
  • Internet connection for downloading the required packages.
  • There must be at least one other system in your network. (For instance, another computer on your local area network, a remote server connected via the Internet, or a virtual machine running locally.)
  • Access to Terminal.

Some packages are required to be installed on your system before enabling SSH. All Ubuntu versions don`t have SSH protocol by default. So, follow these instructions to ensure you enable SSH correctly. 

Check if it has already been installed. 

It seems that the SSH server was already installed on your system based on your Ubuntu version. Before starting the installation process, ensure it has already been installed. To check this out, use the CTRL+ALT+T keyboard shortcut or click on the Terminal icon to open the Terminal. Then, use the following command:

ssh localhost

If the "Connection Refused" message appears on your display, you need to start the SSH installation process explained in the next steps. 

Update your Ubuntu system

Before anything, ensure that you`re using the latest Ubuntu version. You can update your system by running the command below: 

sudo apt update && sudo apt upgrade 

Install the OpenSSH client

You can easily install the OpenSSH client applications and related support files on your Ubuntu system by entering this command at a terminal:

sudo apt install openssh-client

Installing OpenSSH-server on Ubuntu is necessary to accept an SSH connection. Follow the next step to do this. 

Install the OpenSSH server

After you run the instructions for installing the SSH client, you need to accept a connection for the SSH session. Type the following command to install the OpenSSH-server package on your Ubuntu system:

sudo apt install openssh-server

Enable SSH server on Ubuntu

The command below will enable the SSH server on the Ubuntu system:

sudo systemctl enable ssh

During the next step, you need to enable UFW and open the SSH port, as the firewall blocks SSH. Use the UFW firewall to open SSH port 22 and run the following command:

sudo ufw allow ssh

Congratulations. You can use the SSH client to connect to your Ubuntu server now that you have installed and run an SSH server.

After you have enabled SSH on your Ubuntu system, you can go through the process of logging into the remote system. Use the “CTRL+ALT+T” keyboard shortcut to open the Terminal and use the following command: 

ssh username@public_IP -p22

Note: Replace the username and IP address of the Ubuntu system on which you`ve installed SSH. The image below is an example of this:

You may not know the IP address. Don`t worry! You can quickly identify it through the terminal by typing the command:

ip a

The public IP address of the computer that you installed SSH will be shown like this:

Once you have entered all the information, you will be officially logged into the server. You can safely manage it from the comfort of your workstation.

I changed the default port number, but you don`t know how. It`s easy. You only need to run a command in Terminal that will configure your firewall and allow traffic via the specified port. UFW is the default firewall configuration tool. Use the syntax below to configure it with the example of port 2222:

sudo ufw allow from any to any port 2222 proto tcp

It may be necessary to allow traffic to SSH's public IP address if your firewall does not allow traffic to SSH's private IP address.

Note: If you use the default port, 22, the port number does not need to be changed. Port 2222 is defined in the Configure SSH section.

To Start SSH service on Ubuntu, type the following command in Terminal:

sudo systemctl start ssh

To stop, use this command:

sudo systemctl stop ssh

And if you need to restart, use the command below:

sudo systemctl restart ssh

To view the status, run this command:

sudo systemctl status ssh

You may not need the SSH server any more or want to remove or disable it for some reason. The following commands will help you with that:

Temporarily disable SSH on Ubuntu:

sudo systemctl stop ssh

Disable SSH after rebooting completely:

sudo systemctl disable ssh

Remove SSH from Ubuntu:

sudo apt-get remove opnessh-server

Ensure that the firewall rule that opened TCP port 22 for SSH has been removed using the following syntax:

sudo ufw delete allow ssh

You can secure a connection through SSH by using the steps listed above. We tried to answer the most frequently asked questions about enabling SSH on Ubuntu systems. Once you’ve completed these, you can work at the command prompt as an administrator on your machine by establishing a reliable and secure protocol named SSH.  

People also read: 

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.