Home > Operating Systems > Configuring SSH access for VirtualBox Guest Host

Configuring SSH access for VirtualBox Guest Host

A few days back at work, I had to configure a CentOS VM and after I was done with installation on the host itself under VirtualBox I tried doing SSH to the CentOS VM and it didnt let me do that. I had it all configured with NAT and never thought that it will give me such a problem, googling it for a little while for an answer I found the solution… here is a quick howto for setting up SSH access to a VirutalBox VM:

Let <VMname> be the guest machine name (use quotes if it contains spaces), here are the commands that you have to execute for host machine console:

$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort” 2222
$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort” 22
$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol” TCP

The HostPort must be greater than or equal to 1024 since listening on ports 0-1023 needs root permssions (and Virtualbox usually doesn’t).

Once all goes good with the commands, you need to exit out (close it) of the guest Machine (different from a reboot as a reboot will not be enough in this case), restart it and then connect via ssh with:

$ ssh -l username -p 2222 localhost

Replace “localhost” with the host machine IP address if you are connecting from another computer.


Shoaib Mir
shoaibmir[@]gmail.com

Advertisements
Categories: Operating Systems Tags: , , ,
  1. Eric
    October 8, 2009 at 5:59 am

    Can you also state how you allow traffic to your VM? I did what you said above, however that doesn’t work. When I ping the VM, there is no response either.

    Thanks.

  2. October 8, 2009 at 10:09 am

    Eric :

    Can you also state how you allow traffic to your VM? I did what you said above, however that doesn’t work. When I ping the VM, there is no response either.

    Thanks.

    Make sure you have your guest attached to Host Interface in VirtualBox network configuration? VirtualBox network configuration will default to NAT and when using NAT your guest OS will have an IP from different network which will not match to what you have on your host.

    If you attach your guest to host interface and assign an IP belonging to same network as your host, you’ll be able to ping your guest.

  3. October 8, 2009 at 10:27 am

    Eric :

    Can you also state how you allow traffic to your VM? I did what you said above, however that doesn’t work. When I ping the VM, there is no response either.

    Thanks.

    This has to be done through port forwarding as I just mentioned in my post as well. I might have missed something as I did a very quicky howto… You can get more details at –> http://www.linux.com/community/blogs/printblog?index_php?view=article&id=38273&tmpl=component&print=1

  4. Gunnar
    January 27, 2010 at 7:56 am

    I don’t understand why you not all choose to let the interface be bridged instead and get an DHCP-address from the network where you have the other machines? I bridge my virtual machines under VirtualBox, and then it behaves lika any other machine on the local network. No port forwarding.

    Gunnar

  5. January 27, 2010 at 8:40 am

    Not sure as I havent tried that myself but it if does work, that makes more sense then using port forwarding 🙂

  6. Gunnar
    January 28, 2010 at 4:31 am

    shoaibmir :
    Not sure as I havent tried that myself but it if does work, that makes more sense then using port forwarding

    I sure works. I’m using it all the time 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: