How to Establish Remote connection to Linux based Virtual Machines over Internet ?

Dinesh Bhatia
4 min readMar 30, 2023

--

Imagine a scenario where you have created several virtual machines, and you wish to make these machines accessible from any location around the world through the internet with their corresponding login credentials. So here is Flowchart & framework for same:

FLOWCHART
FRAMEWORK

Requirements: Virtual Box, Stable Internet Connection, Router, Linux based Virtual Machines.

Procedure:

  1. To begin, launch the VirtualBox application on your computer and proceed to create a new virtual machine that runs on the Linux operating system.

2. After creating the Linux-based virtual machine, proceed to log into it and open the terminal. Once the terminal is open, install the openssh-server using command :

$ sudo apt install openssh-server

if you get any error saying no installation candidate then just update your linux machine using : $sudo apt-get update

3. After installing openssh-server, the next step is to start the ssh service on the virtual machine. This can be done by executing the following command on the terminal:

$ sudo service ssh start

Once the service is started, it is important to ensure that it is running properly. This can be done by checking the status of the ssh service. To check the status, use the following command:

$ sudo service ssh status

This command will show whether the ssh service is active or inactive, and it will also display other relevant information such as the listening port and the IP address of the virtual machine.

checking status of SSH

4. It is now necessary to configure the ssh file located at /etc/ssh/sshd_config. To do this, use the following command:

$ sudo nano /etc/ssh/sshd_config.

It is important to grant root access permission, which can be seen in the attached photo:

5. Just add line “PermitRootLogin yes” in the end of sshd_config file to give permission then save the file using Ctrl+O=> Enter=>Ctrl+X.

6. Open VirtualBox and navigate to the “Network” tab of the virtual machine settings. Under “Adapter 1”, make sure that the option for “Bridged Adapter” is selected. This allows the virtual machine to connect directly to the network, giving it a unique IP address and allowing it to be accessible from outside the host machine.

7. Now, Check your IPv4 address using $ ifconfig command .

Here we can see IPv4 address is 192.168.1.7
  • Its private IPv4 address, we can now access machine within the private network using command: $ ssh <machine_name>@<ip_address>

To make the virtual machine accessible from anywhere in the world, we need to take additional steps to make it public. This involves configuring port forwarding on the router and obtaining a public IP address for the virtual machine.

8. Access the router’s administration page on our browser. Once we are logged in, we need to add a port forwarding rule that forwards the traffic requesting SSH (Port 22) access of the virtual machine to that particular machine. We can configure this rule by specifying the internal IP address of the virtual machine and the port number to which traffic should be forwarded. This setting can usually be found under the “Advanced” or “Port Forwarding” section of the router’s settings. For Example (image):

Added port forwarding rule to the table

9. Check your Public IP address, just check it by typing “what is my IP” on google.

10. Now we can acces the VM (192.168.1.7) from anywhere in the world with accurate credentials, using public IP address (example: $ ssh dinesh@117.203.142.215) here 117.203.142.215 is my public IP.

  • I was able to access the VM remotely over the internet using Termux on my Android device, as shown in the picture.

You can access Document where I explained working & Creation of Public & Private remote VMs at: https://drive.google.com/file/d/10cW523AEfGw9LCHCDir9Y0C34g6OncXQ/view?usp=sharing

Hope you Like it.

Thanks

--

--