Syncthing on a Raspberry Pi
The setup
I have talked some time ago about moving to Syncthing as one of my duplication tools (it cannot be really called a backup system), which so far has worked all right. But an issue I have is that while I have it installed on my laptop and both partitions of my desktop (separate drives) I need to switch them on and start syncthing so the duplication can happen. Which is a bit of a pain.
The intermediate solution
At some point I want to have set it up as proper backup system. But meanwhile I wanted to have a version that allowed me not to have on at the same time both of my computers. And even facilitate the transference between my desktop partitions (because I was using my laptop as a go-in-between). If I had an Android phone I could do that (well, I have a couple of old ones laying around, but not using them). Instead I thought it would be a good idea to setup one of my Raspberry Pi to do the job. As no much is required in terms of performance, I have decided to use the first one I bought, a model B.
Getting the Raspberry ready
I haven’t touched a Raspberry Pi in a long time, so I was greatly surprised when I found that they have now an app to setup an SD Card: the Raspberry Pi Imager. Fantastic.
I decided to use the Raspberry Pi OS without desktop, as the pi will run without being connected to any monitor, and any work that I need to do on it will be using an SSH connection.
Once you plug the SD Card with the OS, there is a default username and password for the OS. To change that you can follow the instructions on this page. Recommended to do that.
Next step is to setup the wireless, change the hostname and SSH, which can be done using the raspi-config tool.
As a note here, because I heavily use an ssh config file, I had to add an entry for the Pi, adding the setup PreferredAuthentications=password
, otherwise I would get the Too many tries
error. That will change to my normal setup with IdentityFile
once I create the ssh key
SaaS - Syncthing as a service
Now that I can SSH into the machine is time to setup Syncthing. First step is to install it as a deb package (Raspberry Pi OS is derived from Debian).
As we don’t have a desktop on the Pi, and we cannot access anything yet you will want to run the command syncthing --generate=/home/{youruser}/.config/syncthing
. This will create the config.xml
file and the pem
files for Syncthing to operate.
Next step is to modify that config.xml
file. We want to modify the section gui
, changing the address
(the listening address) to 0.0.0.0:8384
. This is done so I can access the gui from any of my other computers. I run syncthing so I can access that website and add a username and password and the use of https to it. I need to read a bit more about Syncthing to make sure that the ip is not fully exposed from the outside (or maybe I can do a better job a setting up that listening address to be only from a local network).
At this point I could setup the connection between my devices, but I want to first complete the setup of Syncthing as a service.
They do have some basic instructions. On the Raspberry Pi OS you want to follow the systemd instructions. And I will set it up as a system level service, as I just want to plug in the Raspberry Pi and have it working, without having to log in (my desktop will get it setup soon but as a user level service)
Couple of things though: when installing the deb package, it installs on /usr/lib/systemd/system
the syncthing@.service
file referenced in the documentation. You don’t want to modify that one, but copy it onto /etc/systemd/system
(if I understood correctly the systemd priority). You want to copy it because we are going to do one modification. We are going to add an the HOME
environment variable. This is needed by Syncthing, but not setup on a system service. You can read the details about Environment here.
We add the line Environment=HOME=/home/{username}
under the [Service]
section. I was hoping to use the specifier %u
, for which some information you can find here. Even when I am running the service as my {username}
account (or at least that is what I think I am doing), it still gets root on %u
. Clearly I need to learn a bit more about Systemd.
Time to do the enable/start, check with journalctl
that the service is running properly, and we are set.
The conclusion
As I am writing this (not at publishing time), my new Raspberry Pi is synchronizing with my other computers. And now I will not need to have the laptop and my desktop up at the same time to get my duplication.
Good.