I would like to ssh into an Ubuntu virtual machine running on Virtual Box on my machine; use Terminal to ssh into a virtual machine running in the same computer

To avoid "why are you doing that? do so and so" answers, here is why I need this: I need to write desktop automation testing that will run on Amazon EC2 but it is very hard to test due to the network delay caused by using VNC.


2 Answers 2


Make sure you are using Bridged Adaptor in the VirtualBox settings. User Pinhead reported that Promiscuous Mode should be set to Allow All.

In an Ubuntu Terminal window, enter the command below to see if the proper software is installed

sudo systemctl status ssh

If not, then use the commands below to install.

sudo apt update
sudo apt install openssh-server

If you do not know the ip address assigned to the Ubuntu virtual machine, then execute the following steps.

  1. Open the Activities overview and start typing Network.
  2. Click on Network to open the panel.
  3. Click on the symbol. You should see a image similar to the image shown below.

  4. You can use either the IPv4 or IPv6 address.

In a macOS Terminal window, enter the command

ssh <username>@<ip address>

For example, if using the username dma and either of the ip addresses from the above image, then both commands below would work.

ssh [email protected]
ssh dma@2001:470:1f11:4a6:281d:ecf9:cd9e:76a8
  • It worked with promiscuous mode "allow all"
    – user356896
    Jan 22, 2020 at 1:34

You have three networking options that can solve this. These are documented in Chapter 6 of the VirtualBox documentation

  • NAT with port forwarding
  • Host Only
  • Bridged

NAT with port forwarding is most similar to what we use every day behind our routers. In VBox, you can create this NAT network at setup port forwarding from the Preferences Pane. You can configure port forwarding the same way you would configure it on a router. In your case, you could forward port 2222 (or whatever free port you like) to 22 on the guest

enter image description here

Host Only Networks is a network in which the Host and the Guests "live" on their own little subnet with their own IP addresses. VBox creates a software interface on your Mac that allows your machine to see it, but that internal network cannot see anything beyond your host. Use this when you need to isolate your testing area from your production area.

A Bridged Network is functionally easier to setup, but not ideal if you're working in a secured network environment (like a corporate network). It uses your host physical network adapter to filter traffic for itself. It appears on your network as a separate host as if it's not even running as a VM. While easy to implement, the downside is that if your network admin has policies and procedures against new hardware appearing on the network, there's going to be a lot of hurdles you'll have to jump through to make it work.

Each one has their pluses and minuses. Since your ultimate goal is to automate processes on an Amazon EC2 instance, which will have a software defined firewall and port forwarding configured, you may want to emulate this setup with NAT and port forwarding. This way, you can flush out any issues as they arise.

You must log in to answer this question.