Raspberry Pi 3 NAS: Debian, Apache, Samba, BitTorrent Sync, BitTorrent [In-Progress]

NAS stands for Network Accessible Storage, but in this post we are taking it to the next level!

I will show you how to build a Raspberry Pi 3 NAS with a few extra features:

  • Using Debian as the OS will be easy to secure and light on resources, but also Debian runs on anything, so almost all of these steps will work on other hardware as well. If you do not want to use a Pi, skip to the “Setting up Networking” step.
  • Apache will share files over the web, and secure them with a password.
  • Samba shares files over the local network.
  • BitTorrent Sync automatically backs up of all my devices in real time.
  • BitTorrent will allow me to remotely download files to my NAS and then access them. This means I can download large or slow files from my phone, or while my laptop is off.

The Hardware

Debian famously runs on anything, so probably any hardware will work, but I wanted to do this with a Raspberry Pi 3 so I picked one up along with a few accessories;

  • Raspberry Pi 3 Model B ($39 on Amazon)
  • Clear acrylic case This is probably unnecessary, but it seemed like a good precaution to protect the Pi and the surfaces it sits on. ($6.95 on Amazon)
  • Touchscreen for the Pi ($21.99 on Amazon) This was kind of a nightmare to set up. I would skip this unless you really want it.

I already had these other three items, but here they are if you want the same ones!

Installing the OS

Debian runs on anything, but it needs to know how. The Raspberry Pi uses a lot of unusual hardware which is not supported by mainstream Debian, so Raspberry Pi have come out with several customized versions which have support for all their hardware.

I decided to use the most lightweight version they offer, Raspbian Jessie Lite. Ideally, I would like to star with just pure Debian, but that would involve building a kernel and that doesn’t sound like fun.

Head over to the official site or click here to get the torrent for Raspbian Jessie.

Now head over to Sourceforge and download Win32DiskImager.

Use that to write the image from the torrent onto the SD card.

If You Decided To Get That Touchscreen…

Like I said, setting it up is a nightmare. I got the “Kuman 3.5 Inch 480×320 TFT Touch Screen” and eventually figured out how to set it up by reading through dozens of angry Amazon comments until I pieced this together.

Open the sd card you wrote the image to. Edit the file “/boot/cmdline.txt” and change its contents to… (All one line)

dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo

Now, edit “/boot/config.txt” and add onto the end…


Go to this GitHub and download the file “waveshare35a.dtb.”

Rename it to “waveshare35a.dtbo” and put it in the directory “/boot/overlays”

That’s all it takes! ;P

Setting Up Networking

Now you will need to eject the sd card and boot up the pi with the screen attached, as well as a usb keyboard.

The default username is pi, and the default password is raspberry.

In order to connect the Pi to Wifi, type “sudo nano /etc/wpa_supplicant/wpa_supplicant.conf” and add the following…

  ssid="YOUR SSID"
  psk="YOUR PSK"

Save that and exit.

Now lets set a static IP.

Select an IP outside the range of your router’s DHCP and then type “sudo nano /etc/network/interfaces”. Find the line that says “iface wlan0 inet manual” and replace it like this…

iface wlan0 inet static

Leave everything before and after that line we replaced, but all all this stuff in place of that line.

Last but not least, run “sudo raspi-config”.

Under boot options, set Desktop/CLI to “console autologin”

Under advanced options, enable ssh server.

Now exit raspi-config and reboot with “sudo reboot.” You can disconnect the keyboard. We will no longer need it. This is a good time to move the Pi to its eventual destination if you would like.

Remote Access

Install Putty or another SSH client and use it to connect to the static IP you just set up.

In order to use SSL, we will need to add another repository to the package manager. Type “sudo nano /etc/apt/sources.list” and add…

deb http://ftp.debian.org/debian jessie-backports main

Now we need to make sure everything is up to date with “sudo apt-get update && sudo apt-get upgrade”

Now let’s install all the things we will need:

sudo apt-get install fail2ban apache2 screenfetch htop nload python-certbot-apache -t jessie-backports && sudo a2enmod rewrite && sudo service apache2 restart

This will install the following:

  • Fail2Ban: Prevents bruteforce ssh attacks.
  • Apache2: Shares files over the web, securely.
  • Screenfetch: Let’s us share sweet screenshots.
  • Htop: Shows resource usage in case there is a problem.
  • Nload: Shows a graphical representation of real-time network usage. Good ambient display.
  • Certbot: Gives us free SSL through LetsEncrypt.

Set Up The Web Server

Change directory to the new webroot with “cd /var/www” and remove the default files with “rmdir html –ignore-fail-on-non-empty”

Edit the default VirtualHost configuration file, “sudo nano /etc/apache2/sites-available/000-default.conf”.

Change the line “DocumentRoot /var/www/html” to “DocumentRoot /var/www” and save the file.