Setting up a Home Server

Hi! Welcome to the first post on this blog where I'm planning to document some technical projects I've worked on for fun. In this first post, I'm going to walk through the process of turning an old laptop I had into a home server where I'm hosting this website.


Why Host on a Home Server?

You might ask - why go through the hassle of setting up a home server, when cloud hosting is so easily accessible these days, as well as probably more reliable, and maybe even cheaper (when you account for the cost of the computer and the fact that many cloud providers have free instance plans). For me, there were two simple reasons:
1. I had an old laptop that was otherwise pretty much useless.
2. (Most importantly) I thought it would be fun.

Old laptop


Setting up the OS

For my home server operating system, I decided to go with Ubuntu Server - I wanted something that I was both relatively familiar with (I've used Ubuntu for work, and previously set up Ubuntu through VMs) and lightweight - hence the server edition. Once I had copied everything I wanted from the Windows filesystem on the old laptop to my new one, I set about getting the OS I needed. I downloaded an ISO file for the latest LTS version of Ubuntu server from the official website and installed Rufus, a tool for creating bootable USB drives. Luckily, I found an old USB stick in a junk drawer (I could see from the files on it that I last used it 7 years ago) and followed the Rufus instructions for loading the ISO file onto it. I then plugged in the USB, and rebooted while pressing F2 in order to access the BIOS. From there, I moved the Ubuntu system on the USB to the top of the boot order and proceeded with the boot process, following most of the Ubuntu defaults (I chose to overwrite and not dual-boot, but either works).


SSH Access

The next step I wanted to take was setting up ssh, so that I could continue setting up the machine while enjoying the benefits of having a new computer. I started by running the following:
1. sudo apt install openssh-server
2. sudo systemctl start ssh && sudo systemctl enable ssh - runs ssh and allows it to start on server startup
3. sudo ufw allow ssh - allows ssh on the Ubuntu firewell
Next, I connected to the machine over ssh for the first time using password authentication and plugged the laptop into an rarely-used socket in a corner of my bedroom so I could ensure it stayed plugged in. Finally, I generated an ssh keypair using ssh-keygen and copied the necessary keys to my new laptop, and then switched to key-based auth and disabled password authentication on the server.


Connecting to the internet

I wanted to use this server to host public websites, including this one - but due to pesky ISP rules, I couldn't directly expose the server to the internet. I decided to use a Cloudflare tunnel to get around this restriction - Cloudflare tunnels are a tool that allows a host behind a private network to be publicly exposed via a daemon which runs on the host and proactively reaches out to Cloudflare. I won't go through the full details of that here, since Cloudflare has a pretty good guide on their website. First, I registered this domain with cloudflare, and followed the instructions to set up the tunnel, which mainly consisted of installing cloudflared and starting it with appropriate config files. I then tested it out by starting a simple server (my go to is python -m http.server for this kind of thing) in a directory with a bare-bones html file, and confirmed that I could see that file displayed when I navigated to milocasonsnow.com.
At this point, I declared victory in my server setup - stay tuned for further posts on other projects I've worked on, including a more detailed setup of this website!