Create a gist now

Instantly share code, notes, and snippets.

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
address 192.168.56.10
netmask 255.255.255.0

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

sources:

@sebastianconcept

awesome. Thanks for sharing o/

@jchris
jchris commented Oct 19, 2014

worked for me also, thanks!

@jbodah
jbodah commented Nov 17, 2014

In case you can't find vboxnet0 try this:

VirtualBox > Preferences > Network > Host-only Networks > Add host-only network (lns)

@sovanna
sovanna commented Jun 3, 2015

thanks a lot !

@chadb
chadb commented Sep 21, 2015

Thank you.

@ksteigerwald

High Five

@haringsrob

Nice one! Thumbs up ;)

@pauldanielvidal

Thanks for this info, it help it a lot^^,!

I had a initial problem where i still couldn't reach the vbox through 192.168.56.10...

~ $ ssh 192.168.56.10
ssh: connect to host 192.168.56.10 port 22: Connection refused

Then i checked the "ifconfig" again on the host (MacOSX) and found that vboxnet0's ip address was set to 192.168.100.10

vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:00
    inet 192.168.100.1 netmask 0xffffff00 broadcast 192.168.100.255

I just updated the IP Address in the guest (Ubuntu) /etc/network/interfaces and it worked well.

Again thank you very much^^,

@pkdevesh

Thanks Bunch really helpful

@RamirezAmayaS

Loving you so much right now. Got it working after half a day.

@timea
timea commented Feb 29, 2016

Yes, hug that man! Thanks.

@vivekbhansali

Thank you!

Just one small thing to notice is that network adapter name on guest machine may not be always 'eth1'. You need to check the name and add that accordingly in place of 'eth1' which happened in my case.

@francofabio

Thank you!
A good tip.

@davebeach

Perfect simple and it works!

@ma7rix
ma7rix commented Aug 10, 2016

nice, thanks

@jccorrea

omG! VirtualBox Settings is hidden under Preferences (shortcut Command + " , "). Thanks

@tungpham
tungpham commented Sep 2, 2016

it's not always eth1, you can list out the interfaces with ifconfig -a

@sg-s
sg-s commented Sep 7, 2016 edited

this isn't working for me... and i don't understand how you guys are getting ssh 192.168.56.10 to work...isn't this the same as ssh localhost? When I do this, I can successfully ssh into my host, which isn't very useful.

@roflomglol

Tears of joy! Damn it was really frustrating. For those of you who can't bring eth1 up, try ip link and check which adapter is missing from ifconfig, then update /etc/network/interfaces accordingly.

Thanks for gist, OP!

@nachiket
nachiket commented Nov 3, 2016

now if I could only get X working :)

@rehnd
rehnd commented Nov 15, 2016

I ended up losing my internet connection when doing this, so installing ssh would not work. To fix, I added a third network adapter:

(power off vm) > Settings > Network > Adapter 3 > Check enable > Attached to: NAT

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