Monday, July 15, 2019

Setup an Ubuntu VM instance on a Windows host for remote ssh access

An Ubuntu VM VirtualBox instance running as a guest OS on a Windows host can be remotely accessed via the secured ssh shell but the VirtualBox and the host OS must be configured to allow the networking traffic to pass through the ssh ports. The basic steps are: (a) to configure the Windows firewall, (b) to configure the port forwarding in Oracle VirtualBox, and (c) to install and setup the ssh server on the Ubuntu instance.

Open up the Windows firewall for Oracle VirtualBox
  1. In Windows, search for the Windows Defender Firewall with Advanced Security App and open it.


  2. Select Inbound rules. Check the VirtualBox Manager rules and if they are not enabled, double click and enable the rules.
Forward the TCP ssh ports to the Ubuntu VM
  1. Start Oracle VirtualBox.


  2. Select the Ubuntu VM, e.g. Ubuntu19. Click Settings. Then click Network.


  3. Click Port Forwarding.


  4. Click the Plus icon. Add in a new rule for Ssh with the Host Port set to 3022 and the Guest Port set to 22.

    Note: 3022 would be the port number to use to remotely access the Ubuntu VM.
  5. Click OK to all the dialog boxes.
Install openssh-server on the Ubuntu VM
  1. In Oracle VirtualBox, start the Ubuntu VM, e.g. Ubuntu19.
  2. Optional. If the openssh-server is not installed, then open up a Terminal and run the following command.

    $ sudo apt install openssh-server


  3. After the installation is completed, either reboot or restart the ssh service with the following command.

    $ service ssh restart

Remote access via ssh
  1. On a remote PC, open up a Terminal.
  2. Type in the following command to connect to the remote Ubuntu VM instance.

    $ ssh 192.168.8.157 -p 3022

    Note: where 3022 is the port number and 192.168.8.157 is the example IP address of the Windows PC hosting the Ubuntu VM instance.
    The ssh prompt appears.

No comments: