Remote Login Ubuntu machine using Secured Shell (SSH)

Tutorial 11 -​​ Remote Login​​ Ubuntu machine using Secured Shell​​ (SSH)

Linux is the base platform and a pre-requisite​​ to configure​​ and integrate​​ the DevOps tools.​​ ​​ 

What you will Learn:

  • How to find ip address of ubuntu machine​​ (3 ways)

  • Remote Login using Secured Shell (SSH)

  • Install SSH client in our windows host machine

  • SSH​​ – Remote Login

How to​​ find IP​​ address of ubuntu machine​​ (3 ways)

In the previous tutorial, we have installed Ubuntu linux VM on our windows host machine and we were able to connect to VM terminal.​​ 

We have already selected the adapter in our previous tutorial. Before proceeding further, please make sure that you have selected the correct adapter (Wi-Fi or cabled) from the ‘Name’ dropdown. If you don’t do this, the network of virtual machine and your host machine will not match. For example, your host machine might be on the network 192.168.0 and VM would be on 10.0.1. This will not work. Even VM should be on 192.168.0 network

If you have changed the above setting now, just restart your VM machine once.

Execute the ‘ip addr show’ command to find out the ip address of your VM. As seen below, the ip address is 192.168.0.106 (this might be different in your case)

You can also execute ‘ip a’ to find the IP address

You can also execute ‘ifconfig’ command to get the ip address. Notice that when we execute this command,​​ you​​ might be asked to first execute ‘sudo apt install net-tools

So let us execute ‘sudo apt install net-tools’.​​ 

Please note that ‘sudo’ gives us administrative privileges.​​ The sudo​​ superuser​​ password is the same password that you must have given when you were setting up your Ubuntu​​ machine. If you have forgotten the password, you can refer the next tutorial that will guide you how to reset the forgotten password

Now you can execute ‘ifconfig’ command to get the ip address

So we have seen 3 commands that we can use to find the ip address of linux machine.

Let us find out the ip address of our host windows machine

Notice that host windows machine &​​ VM are on same n/w (192.168.0)

Remote​​ Login using Secured Shell (SSH)​​ 

Right now, the guest Ubuntu virtual machine is installed on our host PC and we can easily connect to it. Let us suppose that the virtual machine is physically present at some remote location.​​ How will you then connect to remote virtual machine and start working on it?

We can connect to a remote machine using SSH. However, to do that, SSH should be installed in the virtual machine. ​​ 

By default, Ubuntu does NOT come with ssh installed. Before we install​​ ssh on​​ Ubuntu, execute the below command​​ 
‘sudo apt update’ otherwise you would not be allowed to setup ssh.​​ This command is used to​​ update the machine OS by​​ downloading​​ updated version of packages from internet ​​ 

Next​​ execute below command to install ssh on Ubuntu server ‘sudo apt install openssh-server’.​​ Enter the password when prompted and enter Y to​​ continue with the installation



Next execute below command​​ ‘sudo systemctl status ssh. If you see ‘active (running)’, it means ssh is installed and is running

Press​​ ‘q’​​ to get back to the command line prompt.

Next​​ execute ‘sudo ufw allow ssh.​​ UFW stands for 'uncomplicated firewall'. Using this command, we are setting up a firewall rule to ensure that SSH port (22) on VM is open to remote connections

The command​​ ‘sudo ufw allow 22’ also serves the same purpose.

Install SSH client in our windows host machine

To install SSH client in windows host machine, type ‘settings’ in the ‘Type here to search’ field

Open the Settings

Click ‘Apps’

Select ‘Apps & Features’ as seen below

Click ‘Optional features’ link

Click ‘Add a feature’

Type ‘OpenSSH Client’ in the search file

You will see ‘OpenSSH​​ Client’

Select it and install it

Now when you type ‘ssh’ in the ‘Installed features’, you should see ‘OpenSSH Client’

SSH – Remote Login

Let us open the command prompt from our​​ local​​ windows host machine and check if we can connect to Ubuntu VM using SSH.

Open command prompt, type​​ ‘ssh’​​ and hit Enter. Notice below that SSH​​ client​​ is present​​ in our windows machine

To connect to remote server, the syntax is:​​ 
ssh username@ipaddress of VM

Type​​ ‘yes’,​​ Hit Enter

Enter superuser password

See the last line,​​ we have successfully connected to remote​​ Ubuntu linux​​ virtual machine using SSH!!

We can now execute any linux command​​ on this machine​​ (pwd​​ command is to print​​ ‘present working directory’). We will learn about linux commands in our upcoming tutorials

​​ 

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 10000 RS/149 USD
Attend All Live courses in just 10000 rs / $149 - offer ends 25th April 2024