How to enable SSH on Ubuntu 18.04

s2 0

Secure Shell (SSH) is a cryptographic network protocol used for a secure connection between a client and a server.

In this tutorial, we are going to show you how to enable SSH on an Ubuntu desktop computer. When you enable SSH, you can remotely connect to your Ubuntu computer and securely transfer files or perform administrative tasks.

requirements

Before proceeding with this tutorial, make sure that you are logged in as a user with sudo permissions.

Enable SSH on Ubuntu

The SSH server is not installed by default on Ubuntu desktop systems, but it can be easily installed from the standard Ubuntu repositories.

To install and enable SSH on your Ubuntu system, do the following:

  1. Open your terminal either with the Ctrl+Alt+T Keyboard shortcuts or by clicking the terminal icon and install the openssh-server Package by entering:

    sudo apt updatesudo apt install openssh-server

    Enter the password when prompted and enter Y to continue with the installation.

  2. When the installation is complete, the SSH service will start automatically. To verify that the installation was successful and the SSH service is running, enter the following command which will output the SSH server status:

    sudo systemctl status ssh

    You should see something like Active: active (running) :

    Press q to return to the command line prompt.

  3. Ubuntu comes with a firewall configuration tool called UFW. With the firewall enabled on your system, make sure you open the SSH port:

    sudo ufw allow ssh

Now that SSH is installed and running on your Ubuntu system, you can connect to it via SSH from any remote computer. SSH clients are installed by default on Linux and macOS systems. If you want to connect from a Windows computer, you can use an SSH client such as putty
.

Connect with SSH over LAN

To connect to your Ubuntu computer via LAN, all you have to do is enter the following command:

ssh [email protected]_address
Change that username with the actual username and ip_address with the IP address of the Ubuntu computer on which you installed SSH.

If you don’t know your IP address, you can easily find it using the ip command:

ip a

As you can see from the output, the system IP address is 192.168.121.111.

Once you find the IP address, log into the remote computer by doing the following: ssh
Command:

ssh [email protected]

The first time you’re connecting via SSH, you’ll see a message that looks something like this:

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

Type yes and you will be asked to enter your password.

Warning: Permanently added '192.168.121.111' (ECDSA) to the list of known hosts.
[email protected]'s password:

Once you have entered the password, you will be greeted with a message similar to the following.

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 computer.

Connect to SSH over the Internet

To connect to your Ubuntu computer over the internet, you need to know your public IP address and configure your router to accept data on port 22 and send it to the Ubuntu computer that is running SSH.

To find out the public IP address of the computer you want to SSH connect to, simply go to the following url: https://api.ipify.org

.

When it comes to setting up port forwarding, every router has a different way of setting up port forwarding. Consult your router’s documentation for information on setting up port forwarding. In short, you need to enter the port number that requests will be made to (default SSH port is 22) and the private IP address you found earlier (using the ip a Command) of the computer running SSH.

Once you’ve found the IP address and configured your router, you can log in by typing:

ssh [email protected]_ip_address

There are a few security measures that you should take when exposing your computer to the Internet. The easiest way is to configure your router to accept SSH traffic on a non-standard port and forward it to port 22 on the computer running the SSH service.

You can also set up SSH key-based authentication and connect to your Ubuntu computer without entering a password.

Disabling SSH on Ubuntu

If for some reason you want to disable SSH on your Ubuntu computer, you can simply stop the SSH service by doing the following:

sudo systemctl stop ssh

To start it again, do the following:

sudo systemctl start ssh

To disable the SSH service to start during system startup:

sudo systemctl disable ssh

To enable it again, type:

sudo systemctl enable ssh

diploma

You’ve learned how to install and enable SSH on your Ubuntu 18.04. You can now log in to your computer and perform general system administration tasks from the command prompt.

By default, SSH listens on port 22. Changing the default SSH port adds an extra layer of security to your server by reducing the risk of automated attacks.

If you are managing multiple systems, you can simplify your workflow by defining all of your connections in the SSH configuration file.

For more information on configuring your SSH server, see the Ubuntu documents SSH / OpenSSH / Configure
Instructions and the official SSH manual
Page.

If you have any questions please leave a comment below.