Monday, June 1, 2020

Configure an Ubuntu VirtualBox guest instance for ssh access from the host OS

I use VirtualBox to run guest OS such as Ubuntu 18.04 virtual machines for trying out stuff and experiments to prevent messing up my host operating system, e.g. Ubuntu. For convenience, the guest Ubuntu OS running in the VirtualBox can be accessed remotely from the host OS by creating a network adapter that bridges between the host and the guest. This post describes the configuration needed to allow the host OS to connect to the guest OS remotely through a secured shell (ssh).

The following steps assume an Ubuntu virtual machine has been created in VirtualBox and shutdown.

Create a bridge network adapter
  1. Run VirtualBox.

    The VirtualBox Manager is displayed.

  2. Select the Ubuntu virtual machine e.g. vm1. Click Settings.

    The Settings appear.

  3. Select Network.


  4. Select the Adapter 2 tab. Toggle on the Enable Network Adapter field.


  5. Choose Bridged Adapter in the Attached to field.
  6. In the Name field, choose the network you want the virtual machine to join, e.g. wlp3s0. Click OK.

    The bridged network adapter is created in the virtual machine.
 Identify the virtual machine's IP address on the bridged network
  1. In VirtualBox, run the guest virtual machine, e.g. vm1.
  2. Log in to the guest OS. Open up a Terminal.
  3. Type in the ifconfig command at the prompt:

    A list of network adapters and related information is displayed.


  4. Note down the virtual machine's ip address, e.g. 192.168.0.189.

Install SSH server
If the SSH server is not installed in the guest Ubuntu OS, then do the following steps.
  1. Open a Terminal.
  2. At the prompt, type in the command:

    $ sudo apt-get install openssh-server
  3. At the prompt, type in the command to enable the ssh service.

    $ sudo systemctl enable ssh
  4. Start the ssh service by entering the following command.

    $ sudo systemctl start ssh
Remote access to the guest virtual machine
Now the virtual machine can be accessed from the host operating system. With the virtual machine running, the following commands can be used to access the guest OS.
  1. Open up a Terminal. Type in the following command:

    $ ssh remote_user@192.168.0.189

    Note: where remote_user is the login name for the guest OS and 192.168.0.189 is the IP address of the virtual machine on the host's network.

No comments: