Paul Philippov

How to install Syncthing on a Debian server to serve multiple users

First, Install Syncthing:

sudo -s
curl -s https://syncthing.net/release-key.txt | apt-key add -
echo "deb https://apt.syncthing.net/ syncthing stable" | tee /etc/apt/sources.list.d/syncthing.list
printf "Package: *\nPin: origin apt.syncthing.net\nPin-Priority: 990\n" | tee /etc/apt/preferences.d/syncthing
apt update
apt install syncthing
exit

By default, Syncthing runs on port 8384. In order to serve multiple users, each user has to have a dedicated instance of Syncthing listening on a unique port. I found it easier to assign each user a port in 8390+ range re-using the last digit of user’s UID. The following sequense of commands would make it easier for you to automate the process of creating new istances. Note, that you might need to tweak it if your setup uses multiple IP addresses, or your users’ UIDs are not in the 1000-1009 range.

sudo -s -u <username>
cd
user=$(whoami)
sudo systemctl start syncthing@$user.service
sudo systemctl stop syncthing@$user.service
ip_address=$(hostname -I | xargs)
port=$(echo $UID | sed s/^100/839/)
sed -i "s/127\.0\.0\.1:8384/$ip_address:$port/" ~/.config/syncthing/config.xml
sudo systemctl enable syncthing@$user.service
sudo systemctl start syncthing@$user.service
exit

Open web panel at http://$ip_address:$port and protect future access with login and password.

Also, you might want to mount your server sync directory on your desktop.

Published on March 03, 2021 (8 months ago)

Article tags: debian, syncthing

Comments (0)