Table of Contents
This tip is about the how to enable ssh on Ubuntu 20.04 LTS Linux. So read this free guide, How to enable ssh on Ubuntu 20.04 LTS Linux step by step. If you have query related to same article you may contact us.
How to enable ssh on Ubuntu 20.04 LTS Linux – Guide
What is SSH?
SSH, or Secure Shell, means a network protocol and the software necessary for its use. It works on a dedicated port number which is 22. Therefore, to use SSH on Ubuntu or any other system, port 22 must be allowed on the system’s firewall.
The idea behind using SSH is to establish a secure connection with another computer on the network. However, the remote computer must have an SSH server running, otherwise we will not be able to connect to it using our local computer’s SSH command or client.
Once we have established a connection, a prompt will appear to enter the remote PC user’s password to login and access it in a completely encrypted way. The result of a connection is always identical. you end up up on a command line on the computer, logged in as one of the users there.
Also, we don’t need a PC to connect, even a smartphone can be used. SSH also allows you to control non-monitor computers like NAS boxes, routers and more…
This networking tool is not just limited to Ubuntu, we can use it on macOS, Windows, Rasberry Pi and others even on smartphones
Install and activate Open SSH Server on Ubuntu 20.04
Most of the time Ubuntu comes by default with SSH as an OpenSSH server and the client is already installed on it. However, if you haven’t already done so, please follow the steps provided below. This tutorial is applicable to all active Ubuntu systems, such as Ubuntu 18.04 / 19.04 / 21.04,
Run system update command – sudo apt-get update
Install OpenSSH server on Ubuntu 20.04 LTS-
sudo apt-get install openssh-server openssh-client
Enable and start SSH server services on Ubuntu: sudo systemctl enable –now ssh
To check the status run systemctl status ssh
Enable SSH server on Ubuntu 20.04; check SSH server status on Ubuntu
Once the installation is complete, we can test it by connecting our Ubuntu 20.04 LTS system remotely via SSH using the local computer, which can be a virtual machine. Of course, one thing you need to make sure is that your local system must be able to reach the remote system you want to connect to over the network.
How to Connect remote Ubuntu system via SSH
We will see how to use your local system’s command prompt or terminal to connect to the remote Ubuntu system using SSH.
Here, we are assuming that a remote Ubuntu system has an IP address-192.168.45.23 and the username is h2s; now to establish the connection via ssh follow the steps below:
Open a terminal on your Linux or command prompt on your Windows system.
Use the command syntax “ssh username @ ip-address“. For example – ssh h2s@192.168.45.23.
Since we didn’t connect our Ubuntu server before where we installed the SSH server, the computers don’t “know” each other, of course.
So, when we connect the server for the first time, it will ask you if you really want to connect to the computer and if you trust the displayed signature. Just confirm by typing “yes”.
After that, the process will ask for the remote user’s password, defined in the command when connecting to the server. Enter the password and with it, you will have the remote server command line to issue commands remotely. To exit again, type “exit“.
SSH command to connect to remote Ubuntu 20.04 server
Key Authentication for More Security
Well, instead of entering the remote Ubuntu server password, we can use a more secure form which is the key. In which we don’t need to enter a simple password, preventing our password from being leaked or copied if we are using some unknown computer to connect to the remote server.
The principle of using a key is very simple. We just need to create a key pair on the client machine based on the concept of public and private keys. So basically we are going to create two keys, one is the public key which is used to encrypt the plaintext to convert it into ciphertext while the private key is used by the receiver to decrypt the ciphertext to read the message.
in simple words, the private key is like a doorkey that must remain secret, as you can use it to unlock the remote computer’s door. The public key is basically the keyhole you build into the server door. Therefore, the concept is similar to the real doors present in our houses, everyone can see the keyhole of the Door, but the Key to open is only with the Owner of the house.
Generate public and private keys for SSH
Open the command line – Terminal or Prompt on your local system.
Enter the SSH key generator command that will generate the ssh-keygen key
Press the Enter key.
(optional) You can then enter a password to add an additional barrier when establishing the connection. Otherwise, simply press the Enter key twice if you don’t want the system to prompt you for an additional password lookup.
Finally, two files are created in the hidden “.ssh” directory under your user directory: “id_rsa” and “id_rsa.pub”. The “rsa” in the filename represents the encryption used, but you don’t need to worry about that. The file extension “pub” means “Public”, so it is the public key. Whereas the file without any extension is your private key.
Generate public and private SSH keys
Go to the folder displayed in the command terminal to access the keys:
access secure keys
Copy public key to server
Now, to establish a connection using the key pairs, copy your generated public key to the Ubuntu server here.
We don’t need to visit the server manually, we can use SSH to copy the key too.
Use the following command to copy the SSH public key to the server:
On Linux
ssh-copy-id -i ~ / .ssh / id_rsa.pub username @ ip-address
Note: Change the username and IP address with the actual values of your remote server.
On Windows
scp C: Users windwos-username .ssh id_rsa.pub username @ ip-address: ~ / .ssh / authorized_keys
On MacOS
brew install ssh-copy-id
ssh-copy-id -i ~ / .ssh / id_rsa.pub username @ ip-address
The ”-i” indicates that the identity should be copied, which means the specified public key. Copying is obviously done via SSH, so we need the remote machine password once, here.
Once the key has been copied, you can use your private key to remotely connect and view a system without entering any type of password. However, make sure your private key is in a safe place where it can only be accessed by you.
To use private, here is the command syntax:
ssh -i “path to private key” username @ IP address
path to private key: Replace it with the path where you saved the private key generated by you.
Whereas the username and IP address are for the remote server system details.
In this way, we can use authentication keys to get a connection without a password; remember one thing, this is only possible if you have your private key file with you. Learn more about SSH on the official website.
Please share this article if you like it!
Final note
I hope you like the guide How to enable ssh on Ubuntu 20.04 LTS Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.