Real-time file synchronization across devices using Syncthing

Last edited on 2024-08-04 Tagged under  #syncthing   #lmde   #debian   #linux   #server 

Syncthing is a real-time, continuous file synchronization program. Once installed and configured, it will keep files synced between multiple computers (known as "devices") in real time.

I've been using it as a drop-in replacement for some custom bash scripts and after several days of use have come to love it. Home folders are kept in sync between my Linux desktop, laptop, and home server. Photos are seamlessly transferred from my phone to my computer(s). A photo album hosted on my home server is synced to a tablet now converted into a digital photo frame.

These are my notes from this Youtube tutorial. Well worth watching!

1. Setup

Syncthing is installed on:

2. Release key

Syncthing is under active development and hosts a dedicated Debian package repository for the latest stable release: apt.syncthing.net

Enable the system to check the authenticity of the syncthing packages by adding the release PGP key:

sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg

3. Stable channel

The stable channel is updated with stable release builds, usually every first Tuesday of the month.

Add to the APT sources:

echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

4. Pin

Set a preference for installing Syncthing's own packaged version over the default Debian package by increasing its "pin-priority":

printf "Package: *\nPin: origin apt.syncthing.net\nPin-Priority: 990\n" | sudo tee /etc/apt/preferences.d/syncthing.pref

Update and display the new priorities:

$ sudo apt update
$ apt-cache policy syncthing
syncthing:
  Installed: (none)
  Candidate: 1.27.9
  Version table:
     1.27.9 990
        990 https://apt.syncthing.net syncthing/stable amd64 Packages
     1.27.8 990
        990 https://apt.syncthing.net syncthing/stable amd64 Packages
     1.19.2~ds1-1+b4 500
        500 https://deb.debian.org/debian bookworm/main amd64 Packages

5. Install

sudo apt update && sudo apt install syncthing

6. Autostart

Run Syncthing as a user without requiring root privileges by setting up a systemd user service.

Create a folder to hold user services:

mkdir -p ~/.config/systemd/user

Copy the syncthing.service file into the load path of the user instance:

cp /usr/lib/systemd/user/syncthing.service ~/.config/systemd/user/

Enable and start the service:

systemctl --user enable syncthing.service
systemctl --user start syncthing.service

A default folder for synchronization (~/Sync) is automatically created.

Check the status:

systemctl --user status syncthing.service

View the logs for the user service:

journalctl -e --user-unit=syncthing.service

7. GUI

7.1 Localhost

The admin GUI starts automatically and remains available on localhost:8384.

Go to Actions->Settings->GUI and add a username and password to the web interface.

7.2 Remote host

By default, we can't connect to the GUI running on a remote computer. Syncthing is only listening for connections from 127.0.0.1.

Allow connections to the GUI from network devices by first logging into the remote host, then editing ~/.local/state/syncthing/config.xml.

Change the line:

<gui enabled="true" tls="false" debugging="false" sendBasicAuthPrompt="false">
 <address>127.0.0.1:8384</address>

...to...

<gui enabled="true" tls="true" debugging="false" sendBasicAuthPrompt="false">
 <address>0.0.0.0:8384</address>

Restart:

systemctl --user restart syncthing.service

Remote host is now accessible at <ip_address>:8384.

Go to Actions->Settings-GUI and add a username and password to the web interface.

8. Add devices and folders

See this video tutorial for adding devices and folders for synchronization.

9. Syncthing on Android and ChromeOS

Install on phone and tablet: F-Droid

9.1 Add remote device

  • On the remote device: Actions->Show ID to display QR code
  • On the phone and tablet: Devices, click + to Add Device, click QR icon for Device ID to launch camera app and scan remote device's QR code
  • On the remote device: Click accept to add new device, set config options

9.2 Share phone/tablet folder

Example: Camera folder at /storage/emulated/0/DCIM:

  • On the phone: Click on folder, enable file sharing to the remote device
  • On the remote device: Click accept to add new folder, set config options

10. Resources

You can like, share, or comment on this post on Mastodon 💬

Thanks for reading! Read other posts?

» Next: Converting a tablet into a digital photo frame

« Previous: New life for an old laptop as a Linux home server