How do I connect via ssh to a server running in VirtualBox via NAT?

How do I connect via ssh to a server running in VirtualBox via NAT?

Author: stanislav, 2010-10-13

2 answers

And it is useful to run in "headless" (without GUI) mode:

Http://www.virtualbox.org/manual/ch07.html

To start a virtual machine with VBoxHeadless, you have three options:

You can use

VBoxManage startvm "VM name" --type headless

The extra --type option causes VirtualBox to use VBoxHeadless as the front-end to the internal virtualization engine instead of the Qt front-end.

One alternative is to use VBoxHeadless directly, as follows:

VBoxHeadless --startvm <uuid|name>

This way of starting the VM helps troubleshooting problems reported by VBoxManage startvm ... because you can see sometimes more detailed error messages, especially for early failures before the VM execution is started. In normal situations VBoxManage startvm is preferred since it runs the VM directly as a background process which has to be done explicitly when directly starting VBoxHeadless.

The other alternative is to start VBoxHeadless from the VirtualBox Manager GUI, by holding the Shift key when starting a virtual machine.

Note that when you use VBoxHeadless to start a VM, since the headless server has no other means of output, the VRDP server will always be enabled, regardless of whether you had enabled the VRDP server in the VM's settings. If this is undesirable (for example because you want to access the VM via ssh only), start the VM like this:

VBoxHeadless --startvm <uuid|name> --vrde off

To have the VRDP server enabled depending on the VM configuration, as the other front-ends would, use this:

VBoxHeadless --startvm <uuid|name> --vrde config

If you start the VM with VBoxManage startvm ... then the configuration settings of the VM are always used.

 1
Author: Urban_Hero, 2013-09-23 04:17:39

How do I connect via ssh to a server running on a virtual machine in VirtualBox via NAT?

Let the machine name be x. Then the commands

VBoxManage setextradata x "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP  
VBoxManage setextradata x "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22  
VBoxManage setextradata x "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222

Configure port mapping to the guest machine. And at the command

ssh root@localhost -p 2222

You will be able to connect to the server running on the guest machine.

 0
Author: stanislav, 2010-10-15 17:25:11