How to enable ssh access to a VirtualBox guest

1

Enable ssh access to a virtualbox guest instance using VBoxManage. The guest is the guest machine name and should be quoted if the name contains spaces.

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

I never remember the steps to do this hence a simple script will take care of that in the future.

#!/bin/sh
guest=$1
if [[ $1 == "" ]]
then
	echo "Usage: `basename $0` "
exit 1
fi
VBoxManage setextradata $1 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata $1 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata $1 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

 

1