How to SSH to a VirtualBox from macOS


On macOS (host):

Shutdown your VM and do:

1.VirtualBox > Settings > Network > Add (you will get vboxnet0) Network: Mask:

  1. In the terminal ifconfig will show you new interface vboxnet0
  2. VM’s Settings > System > check “Enable I/O APIC.” VM’s Settings > Network > Adapter 2 > host-only vboxnet0

On Ubuntu 16.04.1 (guest):

  1. Install OpenSSH Server, sudo apt-get install ssh
  2. Run ip link, You should see a list like lo, enp0s3 and enp0s8 or something to that effect. Use that interface name for the below.
  3. Edit /etc/network/interfaces file to append the following lines:
# The loopback network interface
auto loiface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
# The static ip to ssh to
auto enp0s8
iface enp0s8 inet static

Run sudo ifup enp0s8 or sudo shutdown -r now from the Ubuntu command line. SSH server should be up and running.

Switch to your host terminal and enter ssh user@