How to Install SSH on Ubuntu Step-by-step Guide

SSH (Secure SHell) server is used to administer Linux servers remotely. By default, SSH server runs on TCP port 22.

An SSH client is required to connect to the SSH server remotely.

SSH server is very secure. But the only problem is, many bots run on the internet to scan SSH servers open port, if found, these bots try to attack your server.

Security measures must be be taken to mitigate these issues.

Note: On Linux servers, the SSH server is also known as OpenSSH server. They are synonymous in this article.

In this article, I will show you how to install, configure and enable SSH server on Ubuntu Server 18.04 LTS. Let’s get started.

Installing SSH Server:

The OpenSSH server is available in the official package repository of Ubuntu Server 18.04 LTS. So you can install the OpenSSH server using APT package manager.

First update the APT package repository cache of your Ubuntu Server 18.04 LTS with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Now run the following command to install the OpenSSH server:

$ sudo apt install openssh-server

OpenSSH server should be installed.

Starting the SSH Server:

Now check whether your OpenSSH server is running with the following command:

$ sudo systemctl status ssh

In my case, the SSH server is running.

Install SSH Ubuntu

If your SSH server is not running, then you can start it with the following command:

$ sudo systemctl start ssh

Stopping the SSH Server:

At times, you may want to stop the SSH server, so that no one can connect to your Ubuntu 18.04 Server LTS remotely.

To stop the OpenSSH server, run the following command:

$ sudo systemctl stop ssh

Now if you check the status of your SSH Server, you should see that it’s not running.

$ sudo systemctl status ssh

Install SSH Ubuntu

Adding SSH Server to the System Startup:

If you are managing your Ubuntu Server 18.04 LTS remotely most of the time, then you may want your SSH server to start when your computer boots. That way, even if you accidentally restart your computer, you won’t have to go back to your physical server to start the SSH server again before you can connect to your server remotely.

To add the SSH server to the system startup, run the following command:

$ sudo systemctl enable ssh

The SSH service should be added to the system startup.

Install SSH Ubuntu

Connecting to SSH server:

Now that SSH server is installed correctly, all that is left is to connect to it. You can connect to your SSH server from another computer using an SSH client. If your using a Linux based computer as your client, then the SSH client utilities are most likely installed already.

On Windows, you can use PuTTY as an SSH client to connect to your SSH server. Git Bash can also be used. That’s out of the scope of this article.

First find the IP address of your SSH server with the following command:

$ ip a

As you can see, the IP address of my SSH server is 192.168.199.129.

Ubuntu Install SSH Server

To connect to your SSH server, run the following command:

$ ssh USERNAME@HOSTNAME

Here, USERNAME is the login username of your SSH server, and HOSTNAME is the IP address or DNS name of your SSH server.

In my case,

$ ssh [email protected]

Now type in yes and press <Enter> to continue.

Now type in your login user’s password and press <Enter>.

Ubuntu Install SSH Server

You should be connected. Now you can run any commands here.

Once you’re done, you can disconnect from the SSH server with the following command:

$ exit

This tutorial is for beginners who are new to administrating Linux server(s). The steps mentioned above is specifically for Ubuntu Server 18.04 LTS, but the procedure is same for other Linux distributions with little change or same commands.

If you face any difficulties installing/enabling SSH for other Linux OS such as CentOS or Redhat  feel free to ask for in the comments below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here