Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 2

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers

Some time ago, I wrote about using Resilio Sync to easily synchronize images between your digital picture frame and your desktop/laptop. While Resilio Sync is free for basic home use, it requires a license for an advanced personal version and business use.

There is one alternative that had escaped me up to now, which is Syncthing, an open-source, multi-platform software that has been around since 2014 and has consistently been improved over time. It used to be a bit complicated to install but no more!

Syncthing is free and uses strong encryption to ensure that any eavesdropper won’t ever gain access to your data. Just like Resilio and unlike Dropbox, it doesn’t store data anywhere else other than on your computers. There is no central cloud server that might be compromised or that requires a subscription model.

In this article, I will explain the steps to install Syncthing on your Raspberry Pi and Mac.

I will then show you how to sync the images folder so that you can add photos of your laptop/desktop and they will automatically show up on your digital picture frame.

About Syncthing

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 3

Syncthing is a file synchronization program. As the authors say on their homepage “it synchronizes files between two or more computers in real-time, safely protected from prying eyes. Your data is your data alone and you deserve to choose where it is stored, whether it is shared with some third party, and how it’s transmitted over the internet.”

The Syncthing Foundation is a small registered Swedish non-profit foundation that provides support for the infrastructure required to run Syncthing (like the syncthing.net website, discovery servers and build servers). The software was originally written in 2014 by Jakob Borg, Audrius Butkevicius, and Simon Frei and has since been actively maintained on Github by some twenty core contributors.

It works on macOS, Microsoft Windows, Linux, FreeBSD, Solaris, and OpenBSD and doesn’t need IP addresses or advanced configuration. It works across a local network or the Internet. Every machine is identified by an ID which you use to share a folder between your local or remote computers, with friends or colleagues.

It uses forward secrecy to prevent any eavesdropper from ever gaining access to your data, and a strong cryptographic certificate identifies every node (=computer). Only nodes that you have explicitly allowed have access to your data.

On top of this, it is well maintained and free of charge for personal and business use. What’s not to like?

The underlying logic

So how does it work? Syncthing synchronizes folders on remote devices. You know this from Dropbox, but the major difference is that Syncthing does not keep any copies of your files on any servers. The files are only synchronized between the computers that you choose to connect to your folder sharing network.

As a first step, you need to install Syncthing on every computer in your network where you want a copy of your folder. So in the case of a digital picture frame, you would install it on your Raspberry Pi and your everyday computer. You can also install it on every computer in the family so that everybody can add images to the digital picture frame from the comfort of their laptop/desktop.

Secondly, you connect the remote devices with their Device ID.

Thirdly, you then designate the folder(s) that you want to share on all connected nodes (computers).

In our example, we will share the /Pictures/ourphotos folder which is the folder used by our Raspberry Pi image viewer to display your wonderful images on the picture frame.

Installing Syncthing on macOS

Jump to the Download Page of Syncthing, click on “syncthing-macos” version under “Integrations” and download the “Syncthing-xxx.dmg” file. Double-click file and move the app to the Applications folder – as you would with any other software.

Launch the app. You will see an icon in the menu bar; there is nothing shown in the dock. The functionality of the app is limited to the basic functionality, most of the settings are in the browser GUI.

At the top, you can start, pause, and stop the sync process. “Open” will launch a browser window for further settings. “Folders” will show you which folders are being synched. The rest is self-explanatory.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 4

At the top, you can start, pause, and stop the sync process. “Open” will launch a browser window for further settings. “Folders” will show you which folders are being synched. The rest is self-explanatory.

Select “Open” and a browser window will come up. If you can see this, then the installation on your Mac will have been successful.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 5

On a fresh installation, you may see a sample folder under “Folders” and no device under “Remote Devices”.

You don’t need to make any changes at this time. We will first set up Syncthing on your Raspberry Pi.

Installing Syncthing on Microsoft Windows

Jump to the Download Page of Syncthing, click on SyncTrayzor version under “Integrations” and follow the instructions. As I don’t have a Windows machine, I haven’t tried this part, but I would be astonished if it worked much differently than the macOS version. If it does, please let me know.

You don’t need to make any changes at this time. We will first set up Syncthing on your Raspberry Pi.

Installing Syncthing on the Raspberry Pi

This is a bit more complicated than on macOS or Windows but, fear not, I’ll walk you through. Open a Terminal window from your laptop/desktop and connect to your Raspberry Pi with

ssh pi@ip-address-of-your-raspberrypi

Then enter these commands one by one

curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
sudo apt update
sudo apt install syncthing
syncthing

Syncthing will now take a moment to set up the program, and add some files and certificates. It will look like this:

[monitor] 16:34:19 INFO: Default folder created and/or linked to new config
[monitor] 16:34:19 INFO: Starting syncthing
[start] 16:34:19 INFO: syncthing v1.3.3 "Fermium Flea" (go1.13.4 linux-arm) deb@build.syncthing.net 2019-12-08 12:31:26 UTC
[start] 16:34:19 INFO: Generating ECDSA key and certificate for syncthing...
[start] 16:34:19 INFO: Default folder created and/or linked to new config
[start] 16:34:19 INFO: Default config saved. Edit /home/pi/.config/syncthing/config.xml to taste (with Syncthing stopped) or use the GUI
[Z24PT] 16:34:19 INFO: My ID: Z24PTKZ-WVACAUA-VB5ETNF-P4JCZCP-AWN4JBT-XC3LQZC-WAOZ5EF-K3HY4QB
[Z24PT] 16:34:20 INFO: Single thread SHA256 performance is 18 MB/s using crypto/sha256 (18 MB/s using minio/sha256-simd).
[Z24PT] 16:34:21 INFO: Hashing performance is 17.00 MB/s
[Z24PT] 16:34:21 INFO: Overall send rate is unlimited, receive rate is unlimited
[Z24PT] 16:34:21 INFO: No stored folder metadata for "default": recalculating
[Z24PT] 16:34:21 INFO: Using discovery server https://discovery.syncthing.net/v2/?noannounce&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[Z24PT] 16:34:21 INFO: Using discovery server https://discovery-v4.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[Z24PT] 16:34:21 INFO: Using discovery server https://discovery-v6.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[Z24PT] 16:34:21 INFO: QUIC listener ([::]:22000) starting
[Z24PT] 16:34:21 INFO: TCP listener ([::]:22000) starting
[Z24PT] 16:34:21 INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) starting
[Z24PT] 16:34:21 INFO: Ready to synchronize "Default Folder" (default) (sendreceive)
[Z24PT] 16:34:21 INFO: Completed initial scan of sendreceive folder "Default Folder" (default)
[Z24PT] 16:34:21 INFO: Loading HTTPS certificate: open /home/pi/.config/syncthing/https-cert.pem: no such file or directory
[Z24PT] 16:34:21 INFO: Creating new HTTPS certificate
[Z24PT] 16:34:21 INFO: GUI and API listening on 127.0.0.1:8384
[Z24PT] 16:34:21 INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
[Z24PT] 16:34:21 INFO: My name is "raspberrypi"
[Z24PT] 16:34:32 INFO: Detected 3 NAT services
[Z24PT] 16:34:40 INFO: quic://0.0.0.0:22000 detected NAT type: Port restricted NAT
[Z24PT] 16:34:40 INFO: quic://0.0.0.0:22000 resolved external address quic://93.234.249.183:63352 (via stun.syncthing.net:3478)
[Z24PT] 16:34:52 INFO: Joined relay relay://77.70.78.148:22067

When you see this last line, you can terminate the programm with CTRL-C as it doesn’t stop automatically.

Next, open the Syncthing config file with

sudo nano ~/.config/syncthing/config.xml

As a digital picture frame is typically controlled through a Terminal window from another computer, we need to change the IP address from localhost to allow an external browser connection. Look for the paragraph

<gui enabled="true" tls="false">
    <address>127.0.0.1:8384</address>
    <apikey>xu2Y-Ian-jVkADUWCPZxgVfBd0mQ7TDX</apikey>
</gui>

and change the “127.0.0.1” to “0.0.0.0” like this:

Let’s install syncthing as a service so it is launched automatically at boot:

sudo wget https://raw.githubusercontent.com/syncthing/syncthing/master/etc/linux-systemd/system/syncthing%40.service \

At the arrow prompt enter:

-O /etc/systemd/user/syncthing@.service

And finally:

sudo systemctl enable syncthing@pi.service

Reboot your Raspberry Pi and wait three minutes for syncthing to run through the start-up sequence.

sudo reboot

Now connect from your browser with

http://ip-of-your-raspberry-pi:8384

You will probably see a note like this:

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 6

To get rid of this message, go into “Actions” – “Settings” and add a user and a password.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 7

Activating “Use HTTPS for GUI” would probably make sense, but it creates issues in the browser that you have to figure out on every computer. Should you have checked that box and can’t get access anymore, just manually change back the syncthing config file to tls=”false”. It has to do something with Syncthings certificates being self-signed, so it is expected for them not to be trusted. It probably doesn’t matter much to just use HTTP for our purpose.

Sharing a folder across devices and platforms

Now, that we installed Syncthing on all devices, it’s time to share a folder. Create a folder “ourphotos” in the Pictures directory of the Raspberry Pi.

First, in the browser GUI of Syncthing on your Raspberry Pi, you have to add “Remote Devices” that you want to connect to and on their side, this needs to be confirmed.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 8

If you are in a local network, other computers will be suggested to you, if you are connecting over the Internet, you will need the Device ID which you will find in the “Actions > Show ID” dialog on the other device.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 9

Second, click on “Add folder”. Specify the Folder Path and give your folder a label. Do not change the Folder ID, it is created by Syncthing.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 10

In “Sharing”, select your additional devices to share this folder on.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 11

Now, go back to the browser GUI of your other computer (in my case a local MacBook). You will see a message like this:

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 12

When you accept, this window comes up:

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 13

Specify the Folder Path on this computer. If it doesn’t exist yet, it will be created automatically. The name of this folder can be different than the folder on your Raspberry Pi. The only thing that is important is the Folder ID.

That’s it. Your folder is now shared between your Raspberry Pi and your local computer. You can add as many other computers as you want and share as many folders as you like among them.

Using Syncthing to synchronize files between your Rasp­berry Pi and Mac/PC/Linux computers 14

To test the folder sharing, add a few images to either your Raspberry Pi or your local computer. Give it a few seconds and the files will be synchronized on both ends. Delete a file on one other computer, and it will be deleted on the other one.

Conclusion

There are several Syncthing options that you can explore in the browser GUI, like e.g., Versioning where you can specify what should happen with files that have been deleted or replaced.

The most common use case for a digital picture frame is to share the images folder on the frame with your family so that everybody can add images to it from where ever they happen to be. In this case, it is probably a good idea to add subdirectories for each family member to the main “ourphotos” folder to make photo housekeeping easier.

Enjoy, and as always, I’d be glad to hear how this works for you!

Was this article helpful?

Scroll to Top