mac ssh 连接virtualbox 里的debian 系统

If you worked only with a provided harddisk-file, this implies for me that you created the VM yourself. The default network-setting for new VMs is "NAT" so you have to create a NAT-Rule, routing the host's port 22 to the VM's port 22.

I don't know about MacOS, but under Linux, you'd have to use a port > 1024. I usually use ports starting with 10000 and the respective service-port. In your case, I'd make a port-mapping of 10022 -> 22. For the entry in the "host"-column I use 127.0.0.1 and for the guest-side 0.0.0.0 as addresses.

You get to the menu via "Right-click on VM" in VirtualBox Manager -> "Change" -> "Network"-tab -> "Port-Forwarding"

http://yunbbs.b0.upaiyun.com/upload/5/1447861647.png 7

http://yunbbs.b0.upaiyun.com/upload/5/1447861653.png 4

Now you can connect your VM:

ssh root@127.0.0.1 -p 10022

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:

Relative Articles