In this article, we will enable SSH on Ubuntu. SSH stands for Secure Sell and working on TCP port 22. SSH allows you to access your Ubuntu machine remotely. However, the communication between to user and the Ubuntu machine will be very secure.
Note: You must be login using a super user account, i.e. sudo permission!
How to enable SSH on Ubuntu
So, let’s start our configuration step by step. First, we will download the OpenSSH Server. Later, we enable the SSH on the Ubuntu machine. Finally, we will access the ubuntu machine from the remote machine using ssh client. So, let’s start the configuration.
Step 1: Install the OpenSSH Server on Ubuntu Machine
To Enable SSH on Ubuntu, you need to install OpenSSH on the Ubuntu machine. So, access the Ubuntu Terminal either using Alt+Ctrl+T keyboard shortcut or you can click on the Terminal icon.
Note: You must need Internet Connectivity to perform below tasks.
Once, you opened the Terminal, first, you need to update the git repository. You can use the below command to update the git repository.
sudo apt-get update
Once, you updated your git repository, you need to install the OpenSSH Server Package. You can use the below command to install the openssh-server package.
sudo apt-get install openssh-server
You need to enter your superuser password & press Y when prompt.
This command will take some time to execute. It will first download all the required packages for the openssh-server. Later, it will automatically install the open-ssh server on your machine.
Step 2: Enable the Open SSH Service on Ubuntu Machine
Once, you Installed the OpenSSH Server package on your Ubuntu Machine, now you need to enable the SSH service on your machine. By default, the SSH service will be enabled. However, you need to check the service. You can use the below command, to check the status of SSHOpen Server.
service ssh status
The output of this command will be looks like the below image.
Note: Press “q” to exit the output.
Step 3: Getting the Network details from the Ubuntu Machine
Now, we have successfully installed the “OpenSSH Server” or you can say open ssh service on the ubuntu machine. Now, you need to know the IP address of your ubuntu machine to access the remote machine. In case if you don’t know your machine IP, you just need to enter the below command to know the IP address.
Step 4: Allowing SSH from UFW (Firewall) on Ubuntu Machine
UFW stands for Uncomplicated Firewall. This is the Host-Based Firewall which is in Ubuntu Operating System by default. However, this firewall is disabled by default in ubuntu. Although, if you enabled UFW, you need to allow the ssh thought UFW. you can use the below command to allow ssh though it.
sudo ufw allow ssh
Step 5: Accessing Ubuntu from the Remote Machine
Now, for accessing the Ubuntu machine, you need to use SSH Client depending on your Operating System. If you are using Windows System, you can download putty. However, you can enable the SSH from the Windows Feature itself.
If you using Linux or MAC-based systems, you can directly ssh to the Ubuntu Machine. To SSH, to a host, you need to enter the IP address followed by the IP address.
Accessing the Ubuntu Machine using Putty
First, we will access the Ubuntu Machine, using the Putty (i.e. SSH Client). You need to open the putty application and enter the IP address of the Ubuntu Machine.
Once, you hit open, a popup will appear related to SSH Encryption Key. If you want to store the key, you need to click on Yes, however, if you click on No, you will need to click on No as many time as you access the Ubuntu Machine.
Finally, you have the SSH to your ubuntu machine. You can do all administrative related tasks from there.
Accessing the Ubuntu Machine using Remote Linux Machine
Now, we will access the Ubuntu machine from one of the remote Linux. Here, you do not need to install any ssh client. You can directly access the ubuntu using the terminal. You can refer to the below command for SSH using a terminal.
Note: Replace USERNAME & UBUNTU_IP with actuall username and IP.
As you already know, my ubuntu machine username is “gns3network” & the IP address is 172.16.22.161.
So, the original command will be looks like the below command.
The output of this command will be looks like below
The authenticity of host ‘172.16.22.161 (172.16.22.161)’ can’t be established.
ECDSA key fingerprint is SHA256:Y0VoJR0nxwYIMI8jpRijEWQk8SUKYzhTJLjsdvn3uwI.
Are you sure you want to continue connecting (yes/no)?
Since we are connecting to this machine for the first time, so we need to press “Yes”. Once, you press “Yes”, it will be permanently stored to the .ssh folder in the home location. The next output you get will be looks like the below output.
Warning: Permanently added ‘172.16.22.161’ (ECDSA) to the list of known hosts.
Now, you need to enter the password of the Ubuntu machine you want to access. Once, you type the password of the Ubuntu host, you will get access to your remote ubuntu machine.
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-45-generic x86_64)
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
339 packages can be updated.
269 updates are security updates.
Last login: Sun Apr 19 03:12:27 2020 from 172.16.22.162
That’s it! We successfully access the Ubuntu machine from a different remote machine.
Enable SSH on Ubuntu – Q&A
In this session, we will discuss your questions regarding enabling SSH on Ubuntu. You can comment in the comment box for any of your queries.
1. How I can access a Ubuntu Machine Over the Internet?
First, you need to understand the difference between Public IP and Private IP. Once, you read this article, you will know that we must need a public IP to access the Ubuntu Machine from the Internet. If you have a public IP, either you can assign that IP to your machine directly, otherwise, you need to configure your Firewall/Router. You will need to add NAT policies. If you have a limited number of public IP’s, you can also configure Port Forwarding on your Firewall. However, the configuration is different for all the firewalls.
2. It is safe to enable SSH on Ubuntu Machine
Yes, it is very much safe to enable ssh on your ubuntu machine. SSH uses encryption algorithms and generates a key while installing the SSH Server Package, i.e. OpenSSH. All the data will be encrypted using this key. However, it will be unsafe, if someone compromises your SSH Key using some kind of attack.
In this article, we enabled SSH on the ubuntu machine. To enabling the SSH, we first, install the OpenSSH package on the ubuntu machine. Later, we make a rule on UFW to allow ssh through the firewall. Finally, we access the Ubuntu machine using Windows & another Linux machine. We also, discuss several questions related to SSH.
Did you like this article? Share this on Social Media and show us some love 🙂