Setting up a Raspberry Pi home server
host-from-home raspberry-pi dockerIn this section we’ll talk about setting up a Raspberry Pi for use as a home server. This will follow a pretty standard Raspbian install and get us ready to run services as docker containers.
Step 0 - things you’ll need #
The hardware:
- Raspberry Pi (I’ll be using a 3B+ in these examples)
- microSD card
- power supply
- ethernet cable
- case (optional?)
The software:
- Official Raspbian Lite image: https://www.raspberrypi.org/downloads/raspbian/
- Balena Etcher: https://www.balena.io/etcher/
I’m using a Raspberry Pi 3B+, a 4GB class 10 microSD card, and an Anker 5-port 60W usb charger for the power supply. I’m running this on a mac - if you’re running windows or linux your steps might look a little different.
Note: You could potentially get this running using a wifi dongle or they pi’s built-in wifi, but I highly recommend a wired connection.
Step 1 - boot it up #
First we need to flash the OS image onto the microSD card. Insert the microSD card into your card read, and open up Etcher. Follow the prompts to select the Rasbian Lite image you just downloaded, select the microSD card as the disk (probably auto-selected), and then write the image to the card.
Before we fire up the pi, we need to enable ssh since this will be running headless. To do this, just create a file at the root of the boot partition called ssh
.
cd /Volumes/boot
touch ssh
Now we can eject the disk and start up the pi. Plug everything in, and once it boots up you should be able to ssh to your pi and login with the default password raspberry
.
ssh [email protected]
Step 2 - configure #
Start by installing updates:
# update and upgrade
sudo apt-get update
sudo apt-get upgrade
# install software
sudo apt-get install vim
# ssh authorized keys
mkdir .ssh
vim .ssh/authorized_keys
# paste in your key (on host: pbcopy < ~/.ssh/id_ed25519.pub)
# lock down ssh files
chmod 700 .ssh
chmod 400 .ssh/authorized_keys
# remove password
sudo passwd pi -d
Let’s test it out before we continue. Try to ssh in from another terminal and see if it uses your ssh key:
ssh [email protected]
Update /etc/ssh/sshd_config
:
PermitRootLogin no
PasswordAuthentication no
Continue config:
# config via raspi-config
sudo raspi-config
# Network options -> Hostname -> interwebs
# Localization options -> Change locale -> enUS UTF8
# Localization options -> Change timezone -> None/UTC
# Advanced options -> Expand filesystem
# Advanced options -> Memory split -> 16
# Exit -> Reboot now
Log back in after reboot
ssh [email protected]
Step 3 - Install docker #
Install docker
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
# logout and log back in
docker info
Install docker-compose
sudo apt-get install python3-pip lib-ffidev
sudo pip3 install docker-compose
Try it out:
docker run --rm hello-world
Wrapping up #
You now should have your local server up and running on your local network. Docker is installed, so we can easily add services. It’s not yet accessible from the outside world, but we’ll cover that in the next installments.