Syncthing is a free and open-source program to sync files between devices from a local network or remote devices over the internet. It uses a peer-to-peer architecture and continuous file synchronization exchanges data directly between devices in a fully automated way.
Syncthing can be used to keep files and directories synchronized in real-time. All data transmission between multiple devices is safe and encrypted with TLS.
Syncthing key features are:
- LDAP authentication support.
- one-way syncing support.
- Fast syncing speed.
- Use both CLI and GUI
- Cross-platform avaliable on: Linux, Android, Unix, Solaris, Windows and Mac OS X.
In this tutorial, we learn how to install Syncthing on Ubuntu 20.04.
- Two servers with Ubuntu 20.04 installed.
- User with sudo and root access.
- Two configured Public IP address.
Install Syncthing on Ubuntu
Syncthing is available on the official repository. Following the steps to install to add Syncthing repo and install it on Ubuntu.
First, update the system packages with the following command:
Install all dependencies with the following command:
apt-get install gnupg2 curl apt-transport-https
Add and download the release key:
curl -s https://syncthing.net/release-key.txt | apt-key add -
Add the Syncthing repository to APT with the following command:
echo "deb https://apt.syncthing.net/ syncthing release" > /etc/apt/sources.list.d/syncthing.list
Once done, update system packages one more time, and install Syncthing package:
apt-get update apt-get install syncthing
Verify installation by checking the Syncthing version:
syncthing v1.18.1 "Fermium Flea" (go1.16.6 linux-amd64) [email protected] 2021-07-30 12:41:57 UTC [noupgrade]
If you got similar output, then Syncthing is installed successfully.
NOTE: You will need to repeat these same installation steps on the other server.
Create a Systemd Unit File
The next step is to create a systemd unit file, for managing the Syncthing service.
Create a file in /etc/systemd/system/ with the following command.
nano /etc/systemd/system/[email protected]
Add the following lines to the configuration file:
Description=Syncthing - Open Source Continuous File Synchronization for %I
ExecStart=/usr/bin/syncthing -no-browser -gui-address="0.0.0.0:8384" -no-restart -logflags=0 Restart=on-failure
In [Service] part, in line
-gui-address="0.0.0.0:8384" add your Public IP address of the first server and leave the same 8384 port.
Save configuration, and close the file.
Now reload the systemd daemon to apply the configuration:
After the daemon is reloaded, start the Synchting service that pointing to your user with the following command.
systemctl start [email protected]
Verify the status of the Syncthing service:
systemctl status [email protected]
The service should be active (running).
The Synchting service listen on port 8384, you can verify using the ss command.
ss -antpl | grep 8384
LISTEN 0 4096 188.8.131.52:8384 0.0.0.0:* users:(("syncthing",pid=13837,fd=20))
NOTE: Repeat these same steps to the other server.
Configuring Syncthing Web Interface
Open your web browser and access the Syncthing Web Interface with URLs.
Syncthing Web Interface uses port 8384.
After login, you should get the following messages.
Next Go to Actions > Settings > GUI to set up a username, password, and enable the option ‘Use HTTPS for GUI.
Click on the Save button, and you will be redirected to the Syncthing login page that will ask to put new credentials for login.
After Sign in as you can see the connection is now secured with HTTPS.
NOTE: Repeat and configure this process also on the second server.
For directories synchronization, we’ll need to merge and connect both server’s device IDs, add the device ID of each server to another server to sync files.
To do this, go to Actions > Show ID on both servers. You will see the following device identification and QR code.
Now, go to the first Syncthing server. On the bottom where is the section for Remote Devices, click on the button +Add Remote Device.
Provide the device ID of your second server and click on the Save button. Optional, can also add the Device Name, for a clearer view.
On the second server, repeat the same step. Go to Add Remote Device.
And add the Device ID from the first server and click on the Save button.
Will sees from both sides that devices are now Connected.
After successful peering of remote devices, find the Folders section and click on the button +Add Folder. You should see the new following window.
Provide your Backup Folder Name in Folder Label in General Section. Then, go to Sharing card section and you will see the following screen.
Checkmark your device to share this folder. In my case name is server2, and click on the Save button.
Now go to the second server and click on Rescan All button. You should see the following screen and a new pop-up message to add this new folder.
Click on Add button, to add the Backup folder shared on the first server. You should see now the following screen.
Can see now that Folder Backup is synchronized and Up to Date.
Whenever you create or modify any files on the Backup folder on the first server they will be automatically synchronized to the second server, all new directories and files in that Backup folder will be mirrored on the other server.
Configure Send-Only and Receive-Only Folders
Another great feature about Syncthing is that you can configure paired servers to send and receive, also they can be specified to send only and receive only.
Go to section Folders > Chose Desired Backup Folder and click on Edit button and then go to Advanced section card. You will see the following image.
And chose Folder Type for Send Only/Receive Only and click on the Save button.
Configure Ajust Scan Intervals
If you want to free up the CPU and don’t need to watch for sync changes constantly, you can disable Watch for Changes and can set up manually for how many minutes, hours you want to sync changes.
Verifying systemctl service
Go to the desired device either on server1 or server2 and check systemctl service status to see how this works on the backend with the following command.
sudo systemctl status [email protected]
● [email protected] - Syncthing - Open Source Continuous File Synchronization for linoxide Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled) Active: active (running) since Wed 2021-08-25 13:46:53 UTC; 1h 4min ago Docs: man:syncthing(1) Main PID: 15543 (syncthing) Tasks: 13 (limit: 1071) Memory: 29.2M CGroup: /system.slice/system-syncthing.slice/[email protected] ├─15543 /usr/bin/syncthing -no-browser -gui-address=184.108.40.206:8384 -no-restart -logflags=0 └─15548 /usr/bin/syncthing -no-browser -gui-address=220.127.116.11:8384 -no-restart -logflags=0 Aug 25 13:52:58 li1307-51 syncthing: [6TZM3] INFO: Device BPENPLJ-L65BS5D-5HN7UL5-RNI3DQR-YZOR2LB-YFW7BKF-6LMWFXV-A4E3RQY client is "syncthing v1.18.1> Aug 25 13:52:58 li1307-51 syncthing: [6TZM3] INFO: Connection to BPENPLJ-L65BS5D-5HN7UL5-RNI3DQR-YZOR2LB-YFW7BKF-6LMWFXV-A4E3RQY at [2600:3c02::f03c:9> Aug 25 13:53:12 li1307-51 syncthing: [6TZM3] INFO: Established secure connection to BPENPLJ-L65BS5D-5HN7UL5-RNI3DQR-YZOR2LB-YFW7BKF-6LMWFXV-A4E3RQY at> Aug 25 13:53:12 li1307-51 syncthing: [6TZM3] INFO: Device BPENPLJ-L65BS5D-5HN7UL5-RNI3DQR-YZOR2LB-YFW7BKF-6LMWFXV-A4E3RQY client is "syncthing v1.18.1> Aug 25 14:13:42 li1307-51 syncthing: [6TZM3] INFO: Adding folder "Backup" (svkz5-mdnbo) Aug 25 14:13:42 li1307-51 syncthing: [6TZM3] INFO: No stored folder metadata for "svkz5-mdnbo"; recalculating Aug 25 14:13:42 li1307-51 syncthing: [6TZM3] INFO: Ready to synchronize "Backup" (svkz5-mdnbo) (sendreceive) Aug 25 14:13:42 li1307-51 syncthing: [6TZM3] INFO: Completed initial scan of sendreceive folder "Backup" (svkz5-mdnbo)
In this tutorial, we learned how to install Syncthing for synchronizing directories on Ubuntu 20.04. You can use and sync more than two devices and be up to date with directories on all machines.
Please share your experience using Syncthing in the comment section.