Syncthing is peer to peer synchronisation software than run on a lot of platform. To be able to synchronise two devices they need to be both up at the same time. At the moment Syncthing is aimed to be run as a single user. Therefore if we want that several users are using it on the same machine several adjustement will be need.
Syncthing installation
The installation of Syncthing is well describe on their web site, and more particularly for Debian/Ubuntu with a dedicated repository http://apt.syncthing.net/.
Configuration for an user
First launch and connection to the interface
Setup a proxy to acces the web interface:
$ ssh -L 9090:127.0.0.1:8384 domaine.tld
Launch synthing
$ syncthing
Connect to the web interface http://localhost:9090
https://docs.syncthing.net/users/firewall.html#remote-web-gui
Configuration of Syncthing
Change default configuration to allow multiple run of Syncthing (one per user). The main parameters to change are the port that the instance of Syncthing will use for first its web interface and second its connection.
- Device Name: to have a idea of server and user
- Sync Protocol Listen Addresses:
tcp://:22001
(by defaulttcp://:22000
) - GUI Listen Addresses:
127.0.0.1:22002
(by default127.0.0.1:8384
)
If on a server with direct connection to Internet deactivate "Enable NAT traversal" and "Enable Relaying".
After restart you need to restart the ssh proxy with the new GUI Listen port:
$ ssh -L 9090:127.0.0.1:22002 domain.tld
Firewall
You will need to open the firewall to allow entry of the synchronisation so open TCP port corresponding to "Sync Protocol Listen Addresses". If you want a direct access to the web interface without the SSH proxy you could open also the corresponding port.
User setup for automatic start
With the help of systemd
If it does not exist create the systemd user directory:
$ mkdir -p ~/.config/systemd/user/
Create a Syncthing service file to setup the service from the example on the Syncthing github:
$ wget -O ~/.config/systemd/user/syncthing.service \
https://github.com/syncthing/syncthing/raw/master/etc/linux-systemd/user/syncthing.service
It should contain something like the following:
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)
After=network.target
Wants=syncthing-inotify.service
[Service]
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
[Install]
WantedBy=default.target
Activate the script:
$ systemctl --user enable syncthing.service
Now you can start and stop Syncthing using systemd tools. Start Syncthing:
$ systemctl --user start syncthing.service
To allow the start without any connexion of the user as root:
# loginctl enable-linger USER
We then create a crontab entry to start Syncthing at reboot of the computer (crontab -e):
@reboot systemctl --user is-active syncthing.service &>/dev/null || systemctl --user start syncthing.service &> /dev/null
We first test that the service is not running before starting it. We can also test regurlaly that the service is running and if not start it:
To do it every hours:
0 * * * * systemctl --user is-active syncthing.service &>/dev/null || systemctl --user start syncthing.service &> /dev/null