Today I reworked my Obsidian infrastructure setup to use Syncthing (https://syncthing.net/) instead of GitHub so I have complete control over my data. In this post I would like to share my setup with you.
Raspberry Pi as Syncthing Main Server
The main idea is having the Raspberry Pi as the main Syncthing server that is always online. Through relay servers any other client is able to establish a connection to that main server. This is important as Syncthing would at least need two devices that it can sync files properly within real-time.
Let's dive into the technical setup.
Setting up the SD Card
Download Raspbian Imager from https://www.raspberrypi.com/software/.
That software writes the Raspbian OS onto your SD Card. Pick Raspberry Lite (no Desktop) and flash your SD Card.
To automatically connect to WIFI place a wpa_supplicant.conf
into the SD card root folder with the following content:
country=de
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="WiFi SSID"
psk="WiFi password"
}
Additionally, place an empty ssh
file into the root. This triggers an SSH login on the first boot.
Connecting to the Raspberry PI
Next, start the Raspberry with the prepared SD Card. It should automatically connect to your network.
To find the IP you might use an IP Scanner like Angry IP Scanner or if you have access to your router you can just see listed devices there. If this is your only raspberry pi in the network try to connecting to
raspberrypi
as ip address.
Connect to it via SSH:
ssh pi@<raspberry pi ip>
Username: pi
Password: raspberry
If you encounter troubles just connect to a display via HDMI and see what the logs show.
After the initial login change the default password to something safe! (or better: enable SSH key authentication only - I will not discuss this here)
passwd
Installing Syncthing
Syncthing is available as a Debian package at https://apt.syncthing.net/:
sudo curl -s -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
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
sudo apt-get update
sudo apt-get install syncthing
Run Syncthing:
syncthing
And note your device Id
This will print starting logs including the Syncthing ID of the raspberry. The line looks like this:
...
[XXXXX] 2022/05/08 16:17:15 INFO: My ID: XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX
...
Exposing the Syncthing Web Console
There is a CLI for Syncthing but it's much easier to maintain configurations via the web browser. Enable it in the ~/.config/syncthing/config.xml
by changing the address
attribute to a 0.0.0.0
value like this:
<gui enabled="true" tls="true">
<address>0.0.0.0:8384</address>
<apikey>xxxxx</apikey>
</gui>
Then, restart syncthing with:
syncthing
And access the web console at https://<raspberry pi ip>:8384
.
Add a new user authentication here to avoid others within the same network of accessing your Syncthing settings. The web console will also prompt you to do this.
Starting Syncthing on Login
To run Syncthing on startup (e.g. when the Raspberry Pi powers up), we can edit the ~/.bashrc
file that gets executed on login of the pi
user:
vi ~/.bashrc
and add the following line to start syncthing:
# ...
# Run Syncthing in detached mode (notice the &)
syncthing serve &
Note that if you login into the pi user the script will always execute. You can also configure a service to run syncthing with init.d or systemd if you want a cleaner execution. The mentioned approach is very simple and sufficient for my case.
Conclusion
This guide walked you through the basic setup of Syncthing on a Raspberry Pi.
You can now start your Raspberry Pi to automatically run Syncthing and access the web console to manage all devices and folders.
Consider adding a backup mechanism to your setup to make it even more robust.