Create a Headless VirtualBox vHost
Install Base Server
- Leave the defaults for the language selection.
- Choose a hostname: VHOST (your choise)
- Enter your name: (John W. Smith)
- Create a username: jsmith
- Create a password for jsmith
- No directory encryption needed
- Verify that the time zone is correct
- for the next windows leave the settings at default unless you want to change them
- At the automatic update I choose “Install Security Updates Automatically”
- When you are prompted to pick your services only choose “OpenSSH Server”(we will add the others as needed)
- —lots of server thinking here—
- Choose yes to install the Boot loader
- Your base installation is finished!
- Reboot
- Login to server after reboot
Secure the Server
- Enable setup firewall
sudo apt-get install ufw sudo ufw enable sudo ufw ufw status verbose sudo ufw allow ssh sudo ufw allow http
- Protect shared memory
sudo vim /etc/fstab
- Add the following line to the document.
tmpfs /dev/shm tmpfs defaults,noexec,nosuid 0 0
- Protect SSH
sudo vim /etc/sshd/sshd_config
- Change PermitRootLogin to NO
PermitRootLogin no
- Only allow admin users to use “su”
- Create an admin group
sudo groupadd admin
- Add your self to the admin group
sudo usermod -a -G admin jsmith
- Restrict access to /bin/su to admin group members
sudo dpkg-statoverride –-update –add root admin 4750 /bin/su
- Check changed permissions
ls -lh /bin/su
- Do not permit source routing of incoming packets
sudo sysctl -w net.ipv4.conf.all.accept_source_route=0
sudo sysctl -w net.ipv4.conf.default.accept_source_route=0
- Install DenyHosts to avoid ssh attacks
sudo apt-get install denyhosts
Install Software
- Now we are going to install the required software for this headless virtual host to work.
sudo vi /etc/apt/sources.list
- Add the following line to the bottom:
deb http://download.virtualbox.org/virtualbox/debian precise contrib
- Then we download the VirtualBox public key…
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
- … and update our package database:
sudo apt-get update
- Afterwards, we install VirtualBox 4.1 as follows:
sudo apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.1 dkms
- Starting with version 4.0, VirtualBox has introduced so called "extension packs" and has outsourced some functionality like remote desktop connection support (VRDP) that was part of VirtualBox packages before version 4.0 into these extension packs. Because we need remote desktop connections to control our virtual machines, we need to install the appropriate extension pack now. Go to http://www.virtualbox.org/wiki/Downloads, and you will find a link to the following extension pack:
VirtualBox 4.1.18 Oracle VM VirtualBox Extension Pack
Support for USB 2.0 devices, VirtualBox RDP and PXE boot for Intel cards.
- Download and install the extension pack as follows:
cd /tmp wget http://download.virtualbox.org/virtualbox/4.1.18/Oracle_VM_VirtualBox_Extension_Pack-4.1.18-78361.vbox-extpack sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.18-78361.vbox-extpack
- Now we must add the user that will run VirtualBox (jsmith in this example) to the vboxusers group:
sudo adduser jsmith vboxusers
Install phpvirtualbox
- First create a system user called vbox and add it to the vboxusers group:
sudo useradd -m vbox -G vboxusers
- Create a password for the vbox user:
sudo passwd vbox
- Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=vbox in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user vbox):
sudo vim /etc/default/virtualbox VBOXWEB_USER=vbox
- save and exit
- Next create the system startup links for vboxwebsrv and start it:
sudo update-rc.d vboxweb-service defaults sudo /etc/init.d/vboxweb-service start
- We need a web server with PHP support to serve phpvirtualbox - I'm using Apache2 here. Install Apache2 and PHP5 as follows:
sudo apt-get install apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common apache2 apache2-doc apache2-suexec libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php5-common php5-mysql php5-suhosin php-pear wget
- Restart Apache2:
sudo service apache2 restart
- I want to serve phpvirtualbox from Apache's default virtual host with the document root /var/www (I will install it in /var/www/phpvirtualbox) - if you have a different document root, you must adjust the following steps:
cd /var/www sudo wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.1-11.zip
- Unzip phpvirtualbox and rename the phpvirtualbox-4.1-11 to phpvirtualbox for ease of use:
sudo unzip phpvirtualbox-4.1-11.zip sudo mv phpvirtualbox-4.1-11 phpvirtualbox
- Next go to the /var/www/phpvirtualbox/ directory…
cd /var/www/phpvirtualbox/
- … and create the file config.php by copying it from config.php-example:
sudo cp config.php-example config.php
- Open config.php and fill in the password you created earlier for the vbox system user:
vi config.php
[...] /* Username / Password for system user that runs VirtualBox */ var $username = 'vbox'; var $password = 'secret'; [...]
- That's it already - you can now open a browser and access phpvirtualbox as follows:
- The default username is admin, the password is admin as well: