xiomi.org logo
RYAN DELANEY

Sep 22, 2022

System Utilities: Syncthing

An abstract blue textured background with the Syncthing logo in the middle

The first component to talk about on the network has been the one I’ve been using most heavily recently. With the semester restarting at university, I had to once again deal with the problem of syncing my files between my devices. You’d think after four years of university I would have figured out a nice way to do this but alas I never quite got there. In those four years, I’ve used a fair few solutions. In my first year I hastily tried to copy notes from one device to another to keep them up to date which was quite a headache in the end with conflicts and figuring out which was most recent and so on. Since then I got gradually more sophisticated and used Git for a while with a private repo which worked well, except for the times I was so certain I’d synced my changes and got home to realise I’d only committed them and hadn’t pushed. This wasn’t too bad when I was 20 minutes away in a lecture but slightly more of a problem when I’m 300 miles away and trying to revise! Since discovering Tailscale I got slightly lower tech but more reliable and used a shared drive on my ODROID-C4 - this worked great except for the inevitable times I was without internet and therefore stranded without my notes. Rarely a problem but certainly bit me more than once

The Saviour Arrives

At the start of the semester I finally started looking around for a better solution and found Syncthing which claims “Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes”. Like Tailscale this has really lived up to its name and has made everything infinitely simpler - even beyond my uni notes.

You can download and install Syncthing from their website.

The Setup

I currently have three devices setup and configured with Syncthing. It doesn’t really have a concept of a central server as you can connect as many remote targets as you want to an install and selectively choose what to share with each - however I decided to setup my ODROID-C4 as effectively a central server so instead of manually configuring each target whenever I update a device, I add one target and have a central source to share files from. The other upsides of this include having an additional backup of my data (for example my notes are now saved across between three and four devices at all times), and it means I don’t need to worry about both devices being on to sync files as my ODROID-C4 will be on an accessible at all times that I have internet (thanks Tailscale!). My sharing setup isn’t huge right now but I get to sync my uni notes and my Minecraft profile, including all my mods which is good enough for me and makes sure my play profile is identical across devices.

image-20220923133046014

Installing and Setting Up

I’ll run through how to configure the setup I am running at home - this assumes that you have three devices and one you want to use as a central node.

1
2
3
4
5
6
7
8
$ # Add the Syncthing release PGP keys
$ sudo curl -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
$ # Add the stable download channel
$ echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
$ # Optional: update apt if it didn't happen automatically
$ sudo apt update
$ # Then install Syncthing!
$ sudo apt install syncthing

This will install syncthing on your system, my systems tend to run Ubuntu based variants so I register my installs with systemd at user level as there’s no need for them to run at system. Thankfully Syncthing provides pre-written systemd service files.

1
2
3
4
5
6
7
8
$ # Make this path if it doesn't already exist, then cd into it
$ cd ~/.config/systemd/user
$ # Download the Syncthing service file
$ wget https://raw.githubusercontent.com/syncthing/syncthing/main/etc/linux-systemd/user/syncthing.service
$ # Update systemd, then enable and start the service so it starts on launch
$ systemctl --user daemon-reload
$ systemctl --user enable syncthing
$ systemctl --user start syncthing

Then you can check the status and you should see something like the following!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ systemctl --user status syncthing
● syncthing.service - Syncthing - Open Source Continuous File Synchronization
Loaded: loaded (/home/ryan/.config/systemd/user/syncthing.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-09-23 12:24:54 BST; 52min ago
Docs: man:syncthing(1)
Main PID: 4800 (syncthing)
Tasks: 23 (limit: 23625)
Memory: 53.7M
CPU: 7.707s
CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/syncthing.service
├─4800 /usr/bin/syncthing serve --no-browser --no-restart --logflags=0
└─4839 /usr/bin/syncthing serve --no-browser --no-restart --logflags=0

Sep 02 13:45:58 ryan-lenovo systemd[3566]: Started Syncthing - Open Source Continuous File Synchronization.
Sep 02 13:45:58 ryan-lenovo syncthing[82767]: [start] INFO: syncthing v1.20.4 "Fermium Flea" (go1.18.4 linux-amd64) [email protected] 2022-08-02 08:10:29 UTC [noupgrade]
...

If that’s working, you can head to http://localhost:8384 and get started with configuration. Setup any authentication you want (all mine is internal so I don’t really worry about it for now). This process is repeated on my other devices, then getting into the setup

On my main node, go to Actions > Show ID and copy the listed ID. Then on my other devices, go to + Add Remote Device at the bottom. Depending on your network setup it may suggest your device to you already, but if not, just paste in the ID you copied before and give it a nice name to help you remember. Back on the main node, make sure to go through and accept the pair requests and if all has gone well your main node should look something like this:

image-20220923132249686

But with everything showing ‘Unused’ - this is because you haven’t shared any folders yet!

To sync from one local device to the other you can follow this simple flow:

  1. On your local device, go to localhost:8384
    1. Hit + Add Folder and fill out the path to your folder and a helpful name
    2. In the Sharing tab, tick your main node device
  2. On your main node, visit the Syncthing interface
    1. Hit Accept on the file share request, and choose a place to sync the folder
    2. Click on the folder in the left pane
    3. Press Edit
    4. In the Sharing tab, tick your other devices
  3. On your other devices, visit localhost:8384
    1. Hit accept on the file share request

Now you should have a copy of the data across all devices and saving on one will propagate changes all the way through the chain of devices.

Moreover, after having set it up as a systemd service and enabling it, the syncthing service will launch on log in and make sure your files are up to date at all times! This guide has so far covered exclusively Linux installs, but Syncthing is available on Linux, Windows, MacOS, Android, Docker, and more, along with community add-ons such as conflict resolution and monitoring - you can find it all on their Community Contributions page. And if you think of something incredible yourself - the entire project is open source (in case the GitHub link earlier wasn’t a give away!) so you can add it and help out the community!

Extra: Joplin

For actually writing and organising my notes I am currently using Joplin notebook which allows me to structure my work into nested notebooks.

image-20220923133117814

I previously used Typora while it was in beta which was incredibly pretty and one of the nicest experiences I’ve had writing in Markdown - and I still use it for one off notes (I’m writing this in it right now) but the one bit that was lacking for me was file structure. While the sidebar supports a file view, it wasn’t as cohesive as I needed for my notes.

Joplin provides quite a similar Markdown experience, although some of my favourite features don’t ship by default (for example image previews in the markdown editor). However, thanks to a rich plugin system - you can just add it and I now can’t function properly without the ‘Enhancement’ plugin. Having everything integrated in one place has been really nice for making and referencing notes and its been a pleasure to work in so far. One attractive feature but that I don’t require right now is the ability to sync your notebooks to external providers including S3, Dropbox and more - which ironically would do exactly what Syncthing does for me but as I said in the first article - I like self hosting things because why not.

OLDER > < NEWER
A magnifying glass, indicating a search button