Sync files across all computers using Syncthing
These are my notes from this Youtube tutorial. Well worth watching!
Syncthing is a continuous file synch program. It synchronizes files between multiple computers in real time.
My setup
My home setup is a star layout; that is, I have multiple devices running Debian - each with Syncthing installed - that exchange data with a central home server.
Example: After travelling and working with my laptop, I return home and - when my laptop connects to the LAN - any file changes are synced with the server, which in turn syncs with the desktop.
1. Keys
Use the latest stable version of Syncthing on Debian by retrieving the package from apt.syncthing.net.
Add the release PGP keys ...
$ sudo curl -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
2. Install
Add the stable channel to the package manager ...
$ 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
Set a preference for Syncthing's packaged version vs Debian's package ...
$ printf "Package: *\nPin: origin apt.syncthing.net\nPin-Priority: 990\n" | sudo tee /etc/apt/preferences.d/syncthing.pref
Install ...
$ sudo apt update && sudo apt install syncthing
3. Startup
On each computer, setup a systemd unit to automate the startup.
Add the systemd service ...
$ wget https://raw.githubusercontent.com/syncthing/syncthing/main/etc/linux-systemd/system/syncthing%40.service
$ sudo chown root: syncthing@.service
$ sudo mv syncthing@.service /etc/systemd/system
$ sudo systemctl daemon-reload
Enable and start Syncthing for your username (example: foo
) ...
$ sudo systemctl enable --now syncthing@foo
$ systemctl status syncthing@foo
A default folder for synchronization - ~/Sync
- is created.
4. GUI
4.1 Localhost
On the local device, access the Syncthing GUI via the following URL: http://127.0.0.1:8384/
Go to Actions->Settings->GUI
and add a username and password to the web interface.
4.2 Remote host
By default, we can't connect to the GUI running on a remote computer (program is only listening for connections from 127.0.0.1
).
Allow connections to the GUI from network devices by logging into the remote computer, then editing ~/.config/syncthing/config.xml
.
Change the line ...
<gui enabled="true" tls="false" debugging="false">
<address>127.0.0.1:8384</address>
... to ...
<gui enabled="true" tls="false" debugging="false">
<address>0.0.0.0:8384</address>
Restart ...
$ sudo systemctl restart syncthing@<username>
Remote host is now accessible at port <ip_address>:8384
.
Go to Settings-GUI
and add a username and password to the web interface.
5. Optional: Allowed networks
By default, Syncthing identifies every device with a unique ID and syncing works between devices both inside the LAN and - courtesy of UPnP - over the Internet.
I find it desirable to only sync between devices from inside my LAN. The Allowed Networks
feature can restrict syncing to only occur through specific subnets. This is set per device from Actions->Advanced->Defaults->Default Device->Allowed Networks
.
Example: To restrict sync to my LAN, I enter 192.168.1.0/24
(for IPv4).
This is obeyed even when global discovery
and/or local discovery
is enabled in settings, which allows Syncthing to find addresses for configured devices but will only attempt connections as permitted.
Link: allowedNetworks
6. Add devices and folders
6.1 Devices
On the remote device, go to Actions->Show ID
, copy the string, and on each local device click on Add remote device
and paste string in Device ID
. A notification appears on remote device to add new device. Click OK and configure.
6.2 Folders
See this video tutorial for adding a folder for synchronization.
7. Syncthing on Android
Install on phone: Google Play
7.1 Add remote device
- On the remote device:
Actions->Show ID
to display QR code - On the phone:
Devices
, click+
toAdd Device
, click QR icon forDevice 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
7.2 Share phone 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
» Next: #1. Libre Space
« Previous: Re-install Linux Mint 21.1 to an existing LVM Logical Volume on LUKS