DIY Syncthing Cloud from Old Raspberry PIs

I used to use dropbox, but having only 5-6 gigs is not really enough if I want to back up my music and or pictures. I had a few raspberries and hard drives from old computers lying around and I though I'd make use of them to store my data redundantly on these, so it's private and I never have to worry about consistency, and what happens if one of them dies on me, nor I have to pay 50+bucks a month for a VM with sufficient storage, nor I have to pay any other cloud services. That said, the places I have these hooked up all have their separate internet addresses, so in case of a blackout I still have other machines to take over. I own 5 of these machines, but I believe 1-2 would already be enough.

I used this article for reference a lot.

What you need?

Setup

Write the Image

Start it up

Install packages

SSH_PORT=3456
sudo apt update && sudo apt install syncthing hdparm ufw
# syncthing: keep your files synced for all devices
# hdparm: spin down drive after a few minutes when not needed to preserve it
# ufw: since this is out on the open web, only allow one port to be open

# allow the SSH port!
sudo ufw allow $SSH_PORT
sudo ufw enable

Configure SSH

Connect a hard drive

Find your device on the internet

In order to log into your device from anywhere, you need to find it on the internet. As most ISPs regularly change your IP address, you can not just save it as it'll change. You need to use a third party service that tracks your IP and maps it to an actual address, like whatever-you-like.dynv6.net . We need to set up a crontab job that runs regularly and keeps the third party - in this case dynv6.net up to date.

Set up dynamic DNS dynv6.net

Create syncthing service

sudo nano /lib/systemd/system/syncthing.service with the content:

[Unit]
Description=SyncthingSynchronization
Documentation=man:syncthing(1)
After=network.target

[Service]
User=pi
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
RestartSec=5
SuccessExitStatus=3 4
RestartForceExitStatus=3 4

# Hardening
ProtectSystem=full
PrivateTmp=true
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

enable and run it with

sudo systemctl enable syncthing
sudo systemctl start syncthing

GUI through SSH Tunnel

If you are using linux, there is a simple way to log into the UI: just add a port redirect into your SSH config file ~/.ssh/config:

Host piname
   HostName piname.dynv6.net
   User pi
   Port 3456
   IdentityFile ~/.ssh/id_rsa
   LocalForward 3333 127.0.0.1:8384

Caveats, Bugs, Look out for this

Constant conflicts? Probably becvause you have multiple file systems! This has to do with permissions. Fix: Folder -> Edit -> Advanced -> Ignore permissions: true