Today we are going to be Installing Syncthing On A Raspberry Pi Using Docker & Portainer. This is episode 11 in our Raspberry Pi series.
We recommend that you watch the series from the beginning so you have everything installed correctly to follow this tutorial. However, if you don’t want to do that we will list what you need to have installed in order to successfully install Syncthing on your Raspberry Pi.
- A Raspberry Pi with Raspberry Pi OS installed. We recommend using an SSD for Syncthing.
- Secured Raspberry Pi.
- Openmediavault, Docker and Portainer Installed.
- A volume created in Openmediavault to be used for Syncthing data storage (Appdata folder).
- Good Internet Connection
Step 1 – Create the Appdata Folders.
You will need to create three folders in your Appdata folder. Or in a folder, you use to store your container data.
The first folder is the root “Syncthing” folder.
Then inside this folder, we will add two folders one is to store the Syncthing config files and the second is to store the synced data.
If your Appdata folder is accessible over the network then you can create these folders using a file explorer from another device on the network.
It is more secure to not expose your Appdata folder directly to the network. Instead, create these folders using a terminal session via secure shell (SSH).
Log into your Raspberry Pi over SSH using a PUTTY or Terminal application:
ssh -p 1984 [email protected]
Once logged in navigate to where your “Appdata” folder is stored.
Now you are in the “Appdata” folder, create the “Syncthing” folder.
Navigate into the “syncthing” folder.
Create the two extra folders.
mkdir config sync
Step 2 – Creating and deploying the Syncthing Stack container.
Now that both folders have been created. Log into your “Portainer” interface using a browser.
Once logged into Portainer click on “Stacks” in the Left hand menu.
Click on “Add Stack“
Name your stack syncthing and copy and paste the following docker compose data into the Web editor:
--- version: "2.1" services: syncthing: image: ghcr.io/linuxserver/syncthing container_name: syncthing hostname: syncthing #optional environment: - PUID=1001 #Add your PUID - PGID=100 #Add your PGID - TZ=Europe/London volumes: - /path/to/Appdata/syncthing/config:/config - /path/to/Appdata/syncthing/sync:/data1 ports: - 8384:8384 - 22000:22000 - 21027:21027/udp restart: unless-stopped
Edit the fields to have your own “PUID” and “PGID” for your docker enabled user account. Add your timezone “TZ” and your “file paths” to your syncthing data folders.
Once complete click on “Deploy the stack“
Once it completes click on “Containers” in the left menu.
Click on the “log icon” next to your new “syncthing” container.
Just make sure that there is no errors showing. If your log looks like our example then all is well.
Step 3 – Configuring the Syncthing GUI
Open your browser and navigate to your new Syncthing interface.
A pop-up box may appear asking if you would like to “Allow Anonymous Usage Reporting?” select an option you are happy with. If you like to keep all your data private opted out by clicking “No“.
You will now see two other notifications which will need to be dealt with before we proceed any further.
Both relate to the same important security task which is to create a Username/Password. So that is what we will do.
Click the “Settings” button on one of the notifications.
Click on the “GUI” tab in the “Settings” pop up window.
Under “GUI Authentication User” add a username. Under “GUI Authentication Password” add a password.
This will be used going forward to log into your Syncthing GUI interface so make sure you store the details somewhere safe.
Note: You can also change the theme here. Dark theme is very easy on the eye :).
Once you have entered both fields click on “Save“.
You will now be logged out. Navigate back to your Syncthing GUI and enter your new Username and Password and log back in.
Step 4 – Setting the correct folders and default folders in Syncthing GUI.
We now want to remove the “Default Folder” from the “Folders” list as this folder is linking to the wrong sync folder location. This step is optional and is only needed if you want to move the Sync folder from the default location. If you are happy using the default location then skip these steps.
Under “Folders” “Default Folder Unshared” click the “Edit” button.
Now click “Remove” to delete the default folder.
By default Syncthing stores the “Sync” folder in “/config/Sync” however we would like to store our data within the same “syncthing” folder but in the directory “/sync”.
When we created our Stack we linked our “sync” folder to the “data1” folder with this line:
To edit the “Folder Path” defaults and make the /data1 permanent for all new future folders that are added to the “Folders” pool and thus ensure that all future folders added to Syncthing go into the correct “sync” folder we need to change the “Default Folder Path” in the “Settings“.
Click on “Actions” in the top right menu.
Now click on “Settings“
The folder we need to add to the “Default Folder Path ” is “/data1/” as this is the “sync” folders mount point within the Docker container.
Once you have added that click “Save“
You can now add your new “sync” folder. From the Syncthing GUI press “Add Folder” under “Folders” section.
Add a “Folder Label” we will call ours “sync“. Then click “Save“.
Step 4 – Create some test data for the sync folder.
We are going to add some test folders and files to our sync folder. This is completely optional and we are only doing this to confirm the “sync” folder is syncing correctly with our Android device once we add it to the device pool.
Your Raspberry Pi’s sync folder is currently not available as a network share over the network in our example as we have not enabled our “sync” folder to act as a network share.
This is by design and for extra security, as we only want our Raspberry Pi to store synced data and not to be accessible over the network except via SSH.
Back to creating the test folders and files. We will do this via SSH.
Connect back to your Pi via SSH and navigate to your Appdata/syncthing/sync data folder.
Create a few test folders in the sync data folder. In our example we added 3 folders. This should be enough to confirm the sync is working as expected.
mkdir test test2 test3
Step 5 – Adding Syncthing to an Android device and adding the Raspberry Pi sync data folder
Now we have our Syncthing server configured and our “sync” folder ready to sync. We can now add another device to our “Remote Devices” pool.
Before we can add our remote device which in our example is an Android tablet. We first need to go to that device and add the Syncthing Android app to the device.
From your device navigate to the “Google Play” store app.
Search for “Syncthing“.
Click “Install” to add the apk to your device.
Once it has downloaded click on “Open” or find the app on your device and double click it to open it.
On the welcome screen click “CONTINUE“
On “Storage Permission” click “GRANT PERMISSION” then click “CONTINUE“.
Click “Allow” when it asks “Allow Syncthing to access photos, media and files on your device?“. Then click “CONTINUE“.
Regarding “Location Permission” this is up to you and completely optional. Just click “FINISH“.
Syncthing will now generate some encryption keys for the TLS/SSL connections this may take a few minutes to complete.
Now click on the top left “hamburger menu” and select “Web GUI“.
Say “No” to “Allow Anonymous Usage Reporting?” unless you want to.
We are now ready to view the devices ID number so we can add it to our “Remote Devices” pool on our Raspberry Pi.
Click on “Actions” Then “Show ID“
You should see your unique device ID and QR code.
We are now going to head back to our Raspberry Pi’s Syncthing GUI. From here we are going to add our Android device to our “Remote Devices” pool.
Under “Remote Devices” click on “Add Remote Device“.
You will now see under “You can select one of these nearby devices” your Android devices ID. If you can not see it please make sure your Android device is connected to the same network as your Raspberry Pi. If it is not you can manually add the “Device ID” and the external Syncthing relays should pick it up through the internet.
Click on the correct ID and give the Device a name in the “Device Name” field. in our example, we have named the Device “Tablet“.
Now in the same window click on the “Sharing” tab in the top “Add Device” menu.
Tick “Auto Accept” and “sync” boxes to add the “sync” folder to the Android device. Then click “Save“.
The device should now be added under “Remote Devices“.
Back on your Android device you now need to wait for the “New Device” notification to pop up. It could take a while for the Syncthing relays to send the notification depending on how you added the device so be patient.
Click “Add Device“.
Rename the device under “Device Name” to something more descriptive. In our example, we named ours “SERVER5” after our Raspberry Pi’s hostname.
When done click “Save“.
Your devices have been fully linked.
We now have to wait for the “sync” folder “New Folder” notification to appear on our Android device so we can finalize and link that folder for syncing. It should appear shortly.
Once it appears click “Add” .
In the next menu, you can edit a few settings. The most important being where you would like the new “sync” folder to save to on the Android device. You can save to either internal or an external SD Card.
In our example we will saved the “sync” folder to our Internal device storage. Click “Save“.
Once the sync has finished you should be able to use your Androids file explorer and navigate to the sync folder. There you will see the test files we created earlier.
Step 6 – Sharing a folder from your Android device to the Raspberry Pi Server
To finish our file syncs off we will now add our Android DCIM “Camera” folder to our Raspberry Pi Server so our pictures and videos will sync up to the server.
On the Android device under “Remote Devices” YOUR DEVICE NAME click on “Edit”.
Click on the “Sharing” tab.
Under “Unshared Folders” tick the Camera checkbox then click “Save“.
As we have set “Auto Accept” for any folders added by this Android device from within the Raspberry Pi Syncthing GUI. The “Camera” folder will be automatically added to the sync folder so nothing else needs to be done.
The “Camera” folder will now sync all added photos and videos to the Raspberry Pi Server’s “sync” folder.
Step 7 – Change a two-way synced folder into a one-way backup.
If we leave things here we only have a folder/file sync. So if we run out of space on our Android device and delete some pictures or videos. These files and folders will also be removed from the Raspberry Pi Server pool.
You may not want this so we will show you how you can remove files from your device but keep them stored safely on your Raspberry Pi. Effectively turning it from a Sync to a Backup :).
On your Android device click on “Actions” in the Top Right menu then click on “Advanced“.
Locate the folder that you want to convert to a backup sync from the list and tap on it to expand the Advanced settings.
Scroll down the settings until you see “Ignore Deleted” Tick the checkbox.
Finally scroll to the bottom of the page and click “Save“.
This folder will now ignore any deleted files or folders that you have removed from your device. Leaving a copy on the Raspberry Pi server. Giving you a backup solution.
This concludes today’s Episode.
We need your support.
We hope you enjoyed this episode and that it was helpful and you got benefit out of it.
If you did, please consider supporting our channel by Subscribing to our YouTube channel, and liking and sharing our content.
If you have any questions or any requests please ask in the comments below or on YouTube.