I recently installed Ubuntu Server 12.04 on Oracle VirtualBox and needed to connect to it using ssh. But was wondering how to access my ubuntu server guest from my ubuntu host (yes, I am using ubuntu as host too.) and got it working with few settings. If you want to first install vitrualbox, here is the howto.
This is how I enabled ssh to virtualbox guest:
- If the virtual guest is running, first shut it down as we need to change some settings for it.
On the Oracle VM Virtual Manager go to File–>Preferences…
On the VirtualBox – Settings window select Network and click the + sign to add a Host-only Networks. You will see a vboxnet0 on the list now.(If you already have this, you can skip this step)
- Now select the Virtual Machine and click Settings. On the Settings window select the Network. The “Adapter 1” Attached to : NAT is used for internet by the virtual machine, so leave as it is. Select “Adapter 2” and check the Enable Network Adapetr checkbox if it is not already checked. On the “Attached to:” choose “Host-only Adapter” and in “Name:” select vboxnet0(The same we created in the above step.) Click OK.
- Now, start the virtual machine guest. Install openssh-server(if not already installed) using the command
sudo apt-get install openssh-server.
Edit the /etc/network/interfaces file with the command
vi /etc/network/interfacesor with any other editor of your choice. And add the following contents in it if not already there.
iface eth1 inet static
You can see the address is 192.168.56.110, the 56 is from the vboxnet0. You can check that by following step 2 and 3, and select the vboxnet0 and hit “Enter” key OR right click on vboxnet0 and choose “Edit host-only network”.
- Now restart networking using command
Now restart the virtual machine guest.
You can now access your guest virtual machine from host through shh using
ssh <username>@192.168.56.110and username can be anything like “root”.
I hope this will help someone and saves his/her day.