How to Set Up a Remote File Server Using Raspberry Pi
by Allen_D in Circuits > Raspberry Pi
1723 Views, 4 Favorites, 0 Comments
How to Set Up a Remote File Server Using Raspberry Pi
In this Instructables, we'll set up a decentralized file server and backup device - one that is much more secure than cloud-based alternatives, and one that is always available no matter where you are in the world (the steps for remote control of your Pi are a bit more technical and marked as "Optional"). Let's get started!
Supplies
For this project you will need the following components:
- Raspberry Pi 4 (any will work, however, including a Pi zero!)
- I Recommend getting a case and fan to keep it cool.
- 32 GB micro SD card - buy one with NOOBS (New Out of Box Software) preinstalled to simplify your installation
- uHDMI / HDMI cable
- USB keyboard/mouse (the kind with a little USB wireless dongle is nice)
- Large USB flash drive (e.g. 1 TB is fine)
You can purchase these items individually or as a kit.
RPI Build
- Assemble your Raspberry Pi, attaching heat sinks, fan, and micro SD card
- If your micro SD card doesn't already have Raspberry Pi OS installed, use Raspberry Pi imager to get the software loaded on it
- Plug in uHDMI cable, power, USB flash drive, and wireless keyboard USB dongle and boot up the system
RPI Initial Setup
- Boot up the system
- Select US English settings, Denver timezone
- Set password, save details
- Run software update
- Restart the Pi
- Connect to local network (Ethernet cable or WiFi)
Enable SSH (Optional)
Enabling SSH will allow you to remotely SSH into the system to maintain it, if needed.
- Open terminal, type “sudo raspi-config"
- Go to Interface -> SSH -> Enable (Or click on menu -> Preferences -> Raspberry Pi Configuration)
- Get IP address: ifconfig -> e.g. 192.168.50.219
- Open Mac/main PC terminal and ssh pi@192.168.50.219 to confirm everything works
Install VNC (Optional)
Enabling VNC will allow you to remotely VNC into the system to maintain it, if needed.
- sudo apt update
- sudo apt install realvnc-vnc-server realvnc-vnc-viewer
- sudo raspi-config
- Go to Interfacing Options, VNC -> Yes
- Test via VNC viewer (https://www.realvnc.com/en/connect/download/viewer/) on Mac/main PC on the same network as Pi is connected to
- Force enable HDMI even if not plugged in (will let VNC run without a monitor plugged in)
- sudo vi /boot/config.txt
- Uncomment the line “hdmi_force_hotplug=1” by removing the “#"
- Restart without HDMI cable plugged in and verify you can still access via the viewer
Install Diode Drive
Diode Drive enables 256bit encrypted tunnel to any "Zone" the Pi is added to. Whenever a file is updated in the Zone, the Pi will sync it / store it. This allows any given team member to always get the most recent files from the Zone without having to be online all the time, or at the same time as other team members.
- Install OpenGL dependency: sudo apt install libglu1-mesa
- Download Diode Drive for Linux ARM
- Set install file properties to “execute” and install
- Run Diode Drive
- Setup Pi account name (you'll invite the Pi to join a Zone via its account name), print backup code, save details
- Configure the default Zone directory to be the base directory of the USB flash drive
- NOTE: If this is not done, for every Zone the Pi is invited to, you'll have to "Unlink Zone", manually move the folder to the USB flash drive, and then "Restore Zone". If you leave the default directory in the Pi's user home folder, you can only store around 1GB of files before filling up the disk.
- In Settings, configure "Auto Accept Invites" by adding your computer's account to the whitelist. This is so that you don't have to manually access your Pi to accept any new zones you create.
Install the Diode CLI (Optional)
The Diode CLI enables secure remote access to the SSH and VNC interfaces. We'll lock the VNC interface to your PC's Diode CLI address so that the _only_ other system that can get to the VNC interface is your PC. As such, you'll need to install the Diode CLI on your PC (if you haven't already).
- Install diode CLI: curl -Ssf https://diode.io/install.sh | sh
- Use “diode time” to show the Pi's Diode CLI client address, copy it (e.g. 0xa334b4306bdc1c3cda9bf7781faa46f964213144)
- On PC, Use “diode time” to show the PC's Diode CLI client address, copy it (e.g. 0x21334ab7F3d1b549012498c69A4120DE2ff03E51)
- Test it:
- On Pi: diode publish -public 22:22,80:80,3030:3030 -private 5900,0x21334ab7F3d1b549012498c69A4120DE2ff03E51
- On PC 0x2133...: diode -bind 15900:0xa334b4306bdc1c3cda9bf7781faa46f964213144:5900 socksd
- On PC 0x2133...: Start VNC Client and open “localhost:15900” and then type in the Pi user (pi), pass (<the pass>)
Configure the Diode CLI to Always Load at Boot (Optional)
This will ensure that if the Pi reboots, the Diode CLI interface will be up and running and ready for you to remotely administrate the system.
- wget https://diode.io/diode.service
- vi diode.service
- Just below [Service] add these lines to delay on startup and to restart the service every 24 hours
- Restart=always
- RuntimeMaxSec=86400
- ExecStartPre=/bin/sleep 60
- Update the “ExecStart” line to
- ExecStart=/home/pi/opt/diode/diode publish -public 22:22,80:80,3030:3030 -private 5900,0x21334ab7F3d1b549012498c69A4120DE2ff03E51
- Move diode.service to /etc/systemd/system/
- sudo mv diode.service /etc/systemd/system/
- Start it and confirm OK (you should see something like the picture below)
- sudo systemctl start diode
- systemctl status diode
- Stop it
- systemctl stop diode
- Enable it on boot
- sudo systemctl enable diode
- Created symlink /etc/systemd/system/multi-user.target.wants/diode.service → /etc/systemd/system/diode.service.
- Restart the Pi and confirm everything works
- VNC from remote computer
- Start terminal on PC -> diode -bind 15900:0xa334b4306bdc1c3cda9bf7781faa46f964213144:5900 socksd
- Start VNC client -> localhost:15900
- SSH from remote computer
- Start terminal on PC -> ssh -o "ProxyCommand=nc -X 5 -x diode.link:1080 %h %p" pi@0xa334b4306bdc1c3cda9bf7781faa46f964213144.diode
- Enter SSH credentials
Invite the Pi As a Diode Drive Team Member
Adding the Pi as a Team Member will enable it to synchronize your files for any Zones it is invited to.
- From your computer, run Diode Drive and invite the Pi's Diode Drive account as a Team Member from one or more of your Zones
- On the Pi, either via VNC or via the LCD/keyboard/mouse interface, open Diode Drive and accept the invitations - the Pi should immediately sync all the files then iteratively keep everything backed up and available to other Team Members from there on out!