How to install and activate SSH on Ubuntu 18.04 : Secure Shell (SSH) is a cryptographic network protocol used for secure connections between clients and servers.
In this tutorial, I will show you how to install and enable SSH on the Ubuntu Desktop operating system. Enabling SSH will allow you to remotely connect to your Ubuntu computer and securely transfer files or perform administrative tasks.
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. How to Create a Sudo User and a Sudo Group on Ubuntu
How to Enable SSH on Ubuntu
SSH servers are not installed by default on Ubuntu desktop systems but can be easily installed from standard Ubuntu repositories.
To install and enable SSH on your Ubuntu system, do the following steps:
Open your terminal using
Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and install the package
openssh-server by typing:
$ sudo apt update
$ sudo apt install openssh-server
Enter the password when prompted and enter it
Y to continue with the installation.
After the installation is complete, the SSH service will start automatically. To verify that the installation was successful and the SSH service is running type the following command which will print the SSH server status:
$ sudo systemctl status ssh
You will see something like
Active: active (running):
q to return to the command line prompt.
Ubuntu comes with a firewall configuration tool called UFW. If the firewall is enabled on your system, make sure to open the SSH port:
$ sudo ufw allow ssh
Now that SSH is installed and running on your Ubuntu system, you can connect via SSH from any remote computer. Linux and macOS systems have an SSH client installed by default. If you want to connect from a Windows computer then you can use an SSH client like PuTTY.
Connecting to SSH via LAN
To connect to your Ubuntu machine via LAN, you just need to enter the following command:
$ ssh [email protected]_address
Change the username with the actual username and
ip_address with IP address 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
Once you have found the IP address, log on to the remote computer by running the following ssh command:
$ ssh [email protected]
When you connect via SSH for the first time, you will see a message that looks like this:
Output 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)?
yes and you will be asked to enter a password or password.
Output 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 one below.
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.
How to Connect to SSH Over the Internet
To connect to your Ubuntu computer via the Internet, you will need to know your public IP Address and configure your router to accept data on the port
22 and send it to the Ubuntu machine where SSH is running.
To determine the public IP address of the computer you are trying to SSH on, simply visit the following URL: https://ifconfig.co/ip.
When setting up port forwarding, each router has a different way of setting up port forwarding. You should consult your router’s documentation on how to set up port forwarding. In short, you need to enter the port number where the request will be made (the default SSH port is 22) and the private IP address that you found earlier (using the ip a command) of the computer where SSH is running.
Once you have found the IP address, and configured your router, you can log in by typing:
$ ssh [email protected]_ip_address
If you are exposing your computer to the Internet, it is a good idea to implement some security measures. The most basic is configuring router You are to receive SSH traffic on a non-standard port and to forward it to port 22 on a computer running SSH services.
You can also set up SSH key based authentication and connect to your Ubuntu computer without entering a password.
How to Disable SSH on Ubuntu
If for some reason you want to disable SSH on your Ubuntu machine, you can stop the SSH service by running:
$ sudo systemctl stop ssh
To start again run:
$ sudo systemctl start ssh
To disable the SSH service to start up during system boot:
$ sudo systemctl disable ssh
To activate it again type:
$ sudo systemctl enable ssh
You have learned how to install and enable SSH on your Ubuntu 18.04. You can now log into your computer and perform common sysadmin tasks via 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 manage multiple systems, you can simplify your workflow by defining all your connections in the SSH configuration file.
For more information, on how to configure your SSH server, read the SSH / OpenSSH / Ubuntu Configuration guide and the official SSH manual page. here.