Skip to content

Instantly share code, notes, and snippets.

Last active January 6, 2024 07:31
Show Gist options
  • Save wacko/5577187 to your computer and use it in GitHub Desktop.
Save wacko/5577187 to your computer and use it in GitHub Desktop.
SSH between Mac OS X host and Virtual Box guest

On Mac OS (host):

Shutdown your VM and do:

VirtualBox > Settings > Network > Add (you will get vboxnet0)

On a terminal ifconfig will show you new interface vboxnet0

VM's Settings > System > check "Enable I/O APIC." VM's Settings > Network > Adapter 2 > host-only vboxnet0

On Ubuntu (guest):

Install OpenSSH Server

Edit /etc/network/interfaces file to append the following lines:

auto eth1
iface eth1 inet static

Run sudo ifup eth1 from the Ubuntu command line. SSH server should be up and running. Switch to your host terminal and enter ssh


Copy link

I needed to setup up port forwarding to make this work. ssh username@localhost -p 2281 worked for me!

Copy link

What if no option for adding HOST-ONLY adapter is available in network config? It only allows me to add NAT adapter...

Copy link

@MichalKrakow File => Host Network Manager => Create.

Copy link

As @chao1995 and @AnalyzePlatypus pointed out the interface name might not be eth1 (as of systemd 197 predictable network interface names are used). In addition, the host-only adapter might not show up in ifconfig because it is not up yet. I made the mistake of setting a static IP address on my first network adapter instead. Running ifconfig -a revealed the correct adapter.

Copy link

cpace6 commented Mar 7, 2018

@crsuarez VB only lists 4 adapters through the GUI but actually supports up to 8 via the command line tool

Copy link

skuo-bl commented Mar 8, 2018

Two network interfaces are needed on the guest to enable it to connect to the internet and allow ssh from host.
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:6c:bb:26 brd ff:ff:ff:ff:ff:ff
3: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:44:3b:96 brd ff:ff:ff:ff:ff:ff

enp0s3 is mapped to NAT and enp0s8 is mapped to vboxnet0 ( Add the following to /etc/network/interfaces and leave the config for enp0s3 as is.

# Add the following
auto enp0s8
iface enp0s8 inet static1

Back on host, ssh should work

Copy link

skuo-bl commented Mar 8, 2018

One more thing, use "Paravirtualized Network" for Host-only Adapter.

Copy link

Since Ubuntu 17.10,use netplan to configure your static IP address。 See my fork for more detail.

Copy link

beesuns commented Apr 18, 2018

I am currently using MacBook Air as host and I have installed virtualbox and run kali linux as guest.

In case you can't find vboxnet0 try this: VirtualBox >Preferences > Network > Host-only Networks > Add host-only network (lns)

When I was trying this, there was only NAT Network option. I can not find Host-only Networks.

Copy link

@beesuns You can create a host-only network adapter via VBoxManage command.

$ VBoxManage hostonlyif create

Copy link

I would like to post some new procedure in the new version of VirtualBox(5.2.12 r122591 (Qt5.6.3)) as follows:
File > Host Network Manager > Create (you will get vboxnet0)
...The rest is the same as above

Copy link

genidma commented Jun 21, 2018

Instructions shared by @AnalyzePlatypus work.

Copy link

ghost commented Nov 14, 2018

Hey i have SSH working from local host MAC to VB ubuntu VM. however from gues os ubuntu i don't have internet connectivity. what do i need to do? do i need to create 3rd adapter or can i use the same adapter for internet as well.?

Copy link

Resolved some difficulty with this by reading a comment on this thread: It was as simple as appending a 0 to the end of the inet value shown for eth1 after invoking ifconfig. Once I replaced (ifconfig's inet output) with, I was able to connect.

Copy link

I had considerable difficulty setting up.

This is what worked for me:
I followed the gist with @chao1995's suggestions.

In the VM:

$ ifconfig
lo        Link encap:Local Loopback 
enp0s8    Link encap:Ethernet ...

My etc/network/interfaces looks like this:

$ sudo nano etc/network/interfaces
GNU nano 2.5.3 
# Added this:
# Local Interface (for SSH)
auto enp0s8
iface enp0s8 inet static

To bring up the service, I ran:

$ sudo ifup enp0s8

In my host terminal:

$ ssh <username>@
Welcome to Ubuntu 16.04.2 LTS ...


Troubleshooting Checklist

In VirtualBox Manager

  • Is Settings > Network > Adaptor 2 set to Host-Only Adaptor (vboxnet0)?
  • Is Settings > System > Enable I/O APIC checked?

In the VM

  • Is OpenSSH installed? ($ sudo apt-get install openssh-server )
  • Have you made the changes to /etc/network/interfaces, replacing eth1 with your interface name from ifconfig ?
  • Have you brought up the adaptor with $ sudo ifup <interface name>?

On your host

  • Have you determined the correct IP address to ssh into? (Runifconfig. Use the value of vboxnet0's inet field. If vboxnet0 is not available, review the section above In VirtualBox Manager)
  • Run ssh <username>@<ip address> and log in.

I hope that helps.
Good luck out there!

thanks for sharing this .. this actually summarizes the issues once can face while enabling it ..

Copy link

bigjoe2000 commented Nov 9, 2019

I had some trouble with this on my Ubuntu 18.04, which uses netplan instead of /etc/network/interfaces

Instead, I modified /etc/netplan/50-cloud-init.yaml to the following (The is the static IP address I chose.)

            dhcp4: true
            dhcp4: no
            addresses: []
    version: 2

After editing the file, run

sudo netplan try

That will allow you to verify it's working before changing the virtual machine's network settings.

Copy link

@bigjoe2000 is correct. Just a add on to this: use tab in yaml file.

Copy link

thomyi commented Mar 3, 2020

Are you doing on the VM's Settings or the VirtualBox preference? When I do an "+" I'm only seeing a new NAT connection created. Thanks!

Copy link

letchke commented May 25, 2020

When I'm trying to ssh in on my host, I'm asked for a password. Neither the host nor the guest pw will work, any idea?

Copy link


Copy link

shiouming commented Nov 3, 2020

VirtualBox UI had been redesigned, the UI for step #1 had been moved to File > Host Network Manager.

I'm not sure which version this change was introduced into, perhaps long time ago? I'm on v6.1.16 for MacOS.

Copy link

End-to-end, enabling connection from MacOS to hosted RHEL8 in VirtualBox 6.1

In VirtualBox (6.1.x):
- File > Host Network Manager ...
- Create (vboxnet0)

For the particular instance of VM (powered off):
- Settings > Network > Adapter 2
- Enable Network Adapter (checked)
- Attached to: Host-only Adapter
- Name: vboxnet0

Start the VM and login as root:
# nmcli dev status
	// Will show that enp0s8 is down
# nmcli con up enp0s8
# nmcli dev set enp0s8 autoconnect yes managed no
# nmcli dev connect enp0s8
# nmcli dev status
	// Will show that enp0s8 is connected
# ifconfig
	// Shows an inet IP address (

From the host (Terminal on MacOS):
$ sudo vim /etc/hosts
		*****  vbox.rhel8
$ ping -c 3 vbox.rhel8
$ ssh-copy-id jubilee@vbox.rhel8
$ ssh jubilee@vbox.rhel8 (using SSH keys, passwordless)

Copy link

When I'm trying to ssh in on my host, I'm asked for a password. Neither the host nor the guest pw will work, any idea?

I am getting permission denied when i try to log in. What password should i be trying? Thanks!

I had the same problem. The reason was: I used "root" user. So, I had added 2 lines into sshd_config (in VM):

PermitRootLogin yes
PasswordAuthentication yes

and then (in VM terminal)
systemctl restart sshd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment