Skip to content

Instantly share code, notes, and snippets.

@wacko
Last active July 13, 2024 00:48
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
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:

@danielverissimo
Copy link

Nice

@shiouming
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.

@jmiremba
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 (192.168.56.101)

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

@Denis-Alexeev
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