While procrastinating from doing any real work this Memorial Day weekend, I decided to utilize an old Raspberry Pi I had laying around to create a home server. My plan was to squeeze as much function as possible out of the small computer. This blog post is meant to illustrate the main features of my server and how I resolved specific issues I ran into.
- Raspberry Pi 3 (Model B)
- Western Digital 2TB Elements Portable External Hard Drive
- SaiTech IT 1 feet USB 3.0 Dual Power Y Shape 2 X Type a to Micro B
- SanDisk 64GB MicroSD
Considering that this server will be accessible from anywhere in the world, I would advise anyone who attempts to make a Pi Server to take security very seriously. I used this tutorial to secure my server. I especially recommend you turn off password login for SSH and only use ssh keys for login.
The installation for PiVPN is pretty straight forward, there’s countless tutorials online that guide you through the installation process. I used this one, which explained the process pretty thoroughly. I recommend using Tunnelblick on Mac and OpenVPN on iOS for connecting to your PiVPN.
Apple Time Machine
I hate backing up my Mac, it takes an eternity and having a hard drive plugged in is so tedious. So the idea of automating this process without having to plug anything in is a dream come true. I followed this GitHub tutorial which is pretty comprehensive. I would recommend giving your Pi a static IP before you begin the tutorial, as doing it later on can cause the Time Machine connection to be more finicky. In order to ensure that my Time Machine always worked, I created a quick script that starts the services needed, I added this script to my /etc/rc.local file so it runs on startup.
Also, you will need a dual power cable for the external hard drive, as seen in the photo in this post. The Raspberry Pi by itself cannot power the hard drive so a dual power cable is needed.
*Note, backups are pretty slow using this method. It takes several hours to backup my ~230GB storage.
I think the whole fun of having your own home server is having a computer that is always running. The Pi Server is perfect for running cron jobs. With a constantly running server, you can automate anything you want. Currently I only have one cron job running:
#Subject SUBJECT="System Update $(date)" # To TOEMAIL="" # Message EMAILMESSAGE="message.txt" uptime > $EMAILMESSAGE vcgencmd measure_temp >> $EMAILMESSAGE # Sending email using /bin/mail mail -s "$SUBJECT" "$TOEMAIL" < $EMAILMESSAGE
This emails me every 3 hours of the day the current uptime of my server and the temperature of the CPU. This is just a basic example of the potential here since my bash scripting skills are subpar, but the possibilities are really endless. You can automate anything you want and schedule it for whenever using your server and Cron.
Controlling an Amazon Echo
Currently, my bedroom at home is decked out with smart appliances that are all connected to an Amazon Echo. There isn’t really any straight forward method to interacting with the Echo or any of the appliances through the command line, so I used alexa-remote-control by Thorsten Gehrig in order to communicate with my Echo through the command line. I followed this tutorial to properly retrieve my cookies and set up the script. A few suggestions on following the tutorial:
- Use Firefox to manually retrieve your cookies, using this plugin.
- Paste all the cookies you retrieve into
/tmp/.alexa.cookie, not just the ones recommended in the tutorial. It didn’t work for me when I only used the cookies recommended in the tutorial.
- Make sure you put the right browser on line 77 of
alexa_remote_control.sh. Go to this site to find the exact name of your browser. If you don’t, you won’t be able to send instructions to your Alexa and it will return a weird error.
Using this library, you can easily communicate with your Alexa and any device connected to your Alexa from anywhere in the world through your server. Furthermore, you can use Cron to schedule tasks through your Alexa.
This was a really fun weekend project. I still have some other things I want to add to my server like: PiHole, more automated scripts, etc. I would recommend a Pi server to any hobbyist, developer, or pretty much anyone that has access to a Raspberry Pi.