Home Web Server 2

As I am currently unable to run a web server due to my broadband connection and lack of suitable hardware, I thought I’d get started by setting up a virtual server. I’ve used VirtualBox for a number of years now, to install and test various Linux distributions and other operating systems.

1. Install Debian

I downloaded the 40MB “Smaller CD” Net Install ISO of Debian 6 from here. The Net Install means you start with a very small ISO file and then download only the packages you need for your installation.

For the virtual machine, I selected minimal specs: 256MB RAM and 8GB dynamically expanding hard drive. Installing Debian on VirtualBox is very straighforward and I won’t go into all the details here. The only thing worth noting is when you are asked what collections of software you want installed on top of your core system. I chose the following options:

tasksel

This, amongst other things, installs Apache HTTP Server, PostgreSQL and OpenSSH, just what we need for a web server. You can run tasksel after installation to bring up these options again and of course you can install individual packages as needed. When Debian boots, it starts these services automatically without need for further configuration.

2. Configure VirtualBox Networking

VirtualBox has a number of options for how the virtual network adapter attaches to the real network of the host operating system. The default is NAT, which means that the host and the virtual machine cannot see each other on the network. However, you can setup port forwarding so that certain ports on the host connect to ports on the virtual machine. I setup the following:

Port Forwarding

You can use any port numbers that are above 1024 and not in use for the Host Port. For the virtual machine, you need to use port 80 for HTTP (to connect to Apache) and port 22 for SSH. Whilst SSH is not strictly necessary for administering the virtual machine, it’s worth doing to more closely replicate a real server environment.

To check Apache is running and view the default homepage type the following into your host web browser:

localhost:9000

3. Setup SSH

To SSH to the new server type the following from the host command prompt:

ssh -p 9010 127.0.0.1

Now log out of the remote computer and back in the host command prompt generate a key by typing:

ssh-keygen -t dsa

You will now want to copy the key to the remote computers folder ~/.ssh/authorized_keys. If the .ssh folder does not already exit on the remote machine, you need to create it and give it the correct permission. On the remote computer type:

mkdir ~/.ssh
chmod 700 ~/.ssh

Note that, although you will be copying into authorized_keys, you do not need to create this folder, it will be generated for you.

Now, back on the host machine, copy the public key over to the remote machine with:

scp -P 9010 ~/.ssh/id_dsa.pub 127.0.0.1:.ssh/authorized_keys

Note that while the -p switch for ssh is lowercase, it is uppercase for scp.

Now, reconnect to the remote machine. This time you should be asked for the passphrase you used when you set up your key. Type it in and connect to the remote machine again.

Most modern linux distributions start the ssh-agent program on boot up, which means that once you’ve typed in your passphrase once, future connections will connect without asking for your password or passphrase. This was the case with my host machine, which runs Ubuntu. For further information about setting up SSH, see this site.

Finally, the default Document Root directory for web pages is in /var/www, so to copy your own index.html file type:

scp -P 9010 ~/broohn.org/index.html root@127.0.0.1:/var/www

Because of the default permissions, you need to connect as root to copy this file over. Now when you refresh your web browser you should see your own home page.

 

 

John