Additions Installation and SSH Access to a Sun VirtualBox

I’ve got the latest release Centos 5.4 Linux running on top of Windows 7 using Sun VirtualBox, so I decided to first find out how to connect to my Linux guest machine from my Windows host machine.

First stop, I need remove a minor irritation that requires me to manually switch my mouse between my Linux and Windows desktops. According to the VirtualBox docs, I have to install the so-called Additions. Basically, they’re drivers that one has to install from within the guest OS (in my case, Centos) to allow the guest to smoothly pass controls to the host OS (in my case, Windows 7). To do this, I had to do the following.

On my Linux window menu, I have to click on Devices, then “Install Guest Additions…” What this does is simply to mount the CD image called VBoxGuestAdditions.iso unto my guest OS. By default, Centos mounts the CD in /media/cdrom. In that folder, we need to run the “VBox…” script that corresponds to the guest OS and in my case it’s VBoxLinuxAdditions.run, as follows:

$ cd /media/cdrom
$ sudo ./VBoxLinuxAdditions.run

Note that one has to run this script with administrator rights, thus the sudo. Also, this script also requires that the Linux kernel headers have been installed already. To install the headers, simply do the following and afterwards try again the above two lines:

$ sudo apt-get install linux-headers ( using apt-get )
$ yum install linux-headers ( using yum )

When the script successfully ends, reboot VirtualBox and your guest OS. The mouse integration between the guest and host OS should be done.

Now it’s time to enable SSH access to my guest OS. Obviously, there must be an SSH server running on the guest. The following command will install and then run the SSH server on Centos:

$ sudo apt-get install openssh-server ( using apt-get )
$ yum install openssh-server ( using yum )

Then on Windows 7, we open the DOS command prompt and go to the VirtualBox installation folder. ( remember right click and run administrator on CMD )

C:\> cd "\Program Files\Sun\VirtualBox"

In this folder we run the following commands:

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

These commands will simply set additional parameters for VirtualBox. In effect, we are simply passing network TCP connections to the host on to the guest OS (which I named Linux in VirtualBox). So any connection to port 2222 of my host OS will be passed to port 22 of the guest OS. To view if the new parameters have been properly added, just do:

VBoxManage getextradata Linux enumerate

Then shutdown the guest OS, restart VirtualBox, then run the guest OS.

Finally, we can try to login via SSH to the guest OS. If the host OS were running Linux, we could easily do this on the command line of the host OS:

ssh -l root -p 2222 localhost

In my case where I use Windows 7 as my host OS, I simply use an SSH client like putty, setting the port number field to 2222 and the hostname field as localhost in putty’s graphical user interface. This is how my putty login looked:

Leave a Reply

Your email address will not be published. Required fields are marked *