Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to enable SSH on Ubuntu 18.04, let’s briefly understand - What is SSH?

SSH (Secure Shell) is a secure networking protocol for remote computer access. It encrypts data sent between the client and the server, ensuring confidentiality and integrity.

It is widely used by system administrators and developers to securely connect and administer remote machines. Learn more about SSH and its benefits in this brief summary.

In this tutorial, you will enable SSH on Ubuntu 18.04. We will also address some of the FAQs related to SSH.

Advantages of SSH

  1. Secure Remote Access: SSH ensures encrypted connections for secure remote administration and command execution.
  2. Data Encryption: It encrypts data transferred between client and server, ensuring confidentiality and preventing unauthorized access.
  3. Password Authentication: SSH offers secure password-based authentication for enhanced user verification.
  4. Port Forwarding: SSH supports port forwarding, enabling secure access to services on remote machines.
  5. File Transfer: SSH facilitates secure file transfer between local and remote systems through protocols like SCP and SFTP.

Prerequisite

In order to complete this tutorial, you need to log in as a user with sudo privileges.

Enabling SSH on Ubuntu

You won't find SSH installed on your system by default though you can easily install it from the standard Ubuntu repositories.

1) To begin with,  use Ctrl+Alt+T on the keyboard to access your terminal. You can also do this by clicking on the terminal icon. Then, install the openssh-server package using the following command:

sudo apt update
sudo apt install openssh-server

2) After that, enter the password when prompted then press Y to continue with the installation.

3) The SSH should start automatically once the installation is complete. The following command can help in verifying the status of the SSH service by printing the SSH server status:

sudo systemctl status ssh

You should be able to see Active: active (running)

Then, press q to return to the command line prompt.

4) You need to open the SSH port in case the UFW firewall is enabled.

sudo ufw allow ssh

Connecting to SSH over LAN

1) You can connect to a nearby device with the help of the Ubuntu servers using the following command:

ssh username@ip_address
Note: Make sure to change the username with the actual user name and ip_address with the IP Address of the Ubuntu machine where you installed SSH.

2) In case you are unaware of your IP address you can easily find it using the following command:

ip a

3) Then, log in to the remote server.

You will then see a message which resembles the below output (for the first time you login through SSH):

Output
The authenticity of host '<ip>' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

4) Once you press yes you will be prompted to enter the password:

Output
Warning: Permanently added '<ip>' (ECDSA) to the list of known hosts.
usernampe@ip's password:

You will then be greeted with the following message:

Output
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-33-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

You are now logged into your Ubuntu Machine.

Connecting to SSH Over the Internet

The basic piece of information required to access your Ubuntu machine is your public IP address and also how to configure your router to accept data on port 22 then send it to the the Ubuntu machine where SSH is running.

You can find out the public IP address by navigating to the following url: https://api.ipify.org.

It is recommended that you refer to your router's documentation so that you get a personalized take on setting up port forwarding. The default port for SSH is port 22 which needs to be entered along with the IP address.

You can then login with the help of the following:

ssh username@public_ip_address

It is also recommended to implement certain security measures such as configuring your router to accept SSH traffic on a non-standard port and to forward it to port 22 on the machine running the SSH service.

You may also set up an SSH key-based authentication to connect to your Ubuntu machine without entering a password.

Disabling SSH on Ubuntu

In the scenario where you need to disable SSH, you can simply stop the SSH service using the following command:

sudo systemctl stop ssh

To start the SSH service again:

sudo systemctl start ssh

In order to disable SSH service to start during system boot:

sudo systemctl disable ssh

In case you wish to re-enable it, use:

sudo systemctl enable ssh

FAQs to Enable SSH on Ubuntu 18.04

What if SSH is already installed on Ubuntu 18.04? 

You can confirm by typing ssh in the terminal. If it's not installed, follow the installation steps.

How can I enable SSH on Ubuntu 18.04? 

SSH is enabled by default after installation. No additional steps are needed to enable it.

How can I check if SSH is running on Ubuntu?

Type sudo systemctl status ssh to check if the SSH service is running.

How to allow SSH access for specific users on Ubuntu? 

Add the desired users to the /etc/ssh/sshd_config file using the AllowUsers directive.

Can I modify the SSH port on Ubuntu 18.04? 

Yes, you can change the default port (22) by editing the /etc/ssh/sshd_config file and modifying the Port directive.

How to restart the SSH service after making changes to the configuration?

Use sudo systemctl restart ssh to restart the SSH service for the changes to take effect.

Is it necessary to install a firewall for SSH security? 

It is highly recommended to set up a firewall like UFW to restrict SSH access and enhance security on Ubuntu.

Conclusion

We hope this detailed tutorial helped you understand how to enable SSH on Ubuntu 18.04.

If you have any queries, please leave a comment below and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.