TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Linux / Storage

Linux: Sync Files Between Servers With Syncthing

Easier to set up and use than NFS or Samba, Syncthing is the way to go when you need to keep data between machines in a constant state of sync.
Oct 15th, 2024 8:00am by
Featued image for: Linux: Sync Files Between Servers With Syncthing

Have you ever wanted to keep files and or folders in sync between Linux machines? You could use Samba or NFS for that, but those solutions aren’t exactly geared toward synchronization. With Syncthing, you can not only set an encrypted sync option but also sync between computers, mobile devices and servers. On top of that, Syncthing is easier to set up and use than the other two options. And when you need to keep data between machines in a constant state of sync, this is the way to go.

I’m going to walk you through the process of installing Syncthing on AlmaLinux and Ubuntu Linux so you can see how easy it is to sync files between the two.

What You’ll Need

The only things you’ll need for this are running instances of both AlmaLinux and Ubuntu Linux and a user with sudo privileges. Of course, you could follow along with two instances of AlmaLinux, two instances of Ubuntu, or two completely different distributions.

With those things at the ready, let’s get Syncthing installed.

Installing Syncthing

The installation of Syncthing on AlmaLinux requires downloading a file, extracting it and then moving a file in the newly created directory. Here are the actual steps:

  1. Log in to your AlmaLinux machine.
  2. Download the latest version of Syncthing with the command: curl -s https://api.github.com/repos/syncthing/syncthing/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -.
  3. Unpack the file with tar xvzf syncthing*tar.gz.
  4. Move the required file with the command sudo mv syncthing-linux*/syncthing /usr/bin.
  5. Verify the installation with syncthing --version.

The Ubuntu installation is even easier. Just follow these steps:

  1. Open a terminal window.
  2. Issue the command sudo apt-get install syncthing -y.
  3. Allow the installation to complete.

Creating a Systemd File

To make Syncthing run as a service on a systemd-enabled distribution, you have to create a systemd file with the command:


Notice the @ symbol? That’s there so you can start the Syncthing as a user.

In that file, paste the following:


Save and close the file.

Reload the systemd daemon with:


Let’s say you want to run Syncthing as user “jack”. The command to start and enable the service would be:


Do the same thing on both AlmaLinux and Ubuntu.

Allow Syncthing Through the firewall

Since we’re using two different distributions, you’ll need to use two different firewall tools. On AlmaLinux, we’ll open the firewall ports with the following:


For Ubuntu, the firewall can be opened with the following commands:

Configure Syncthing

Open the Syncthing configuration file with the command:


In that file, look for the following section:

Change tls="false" to tls="true" and make sure the address section is configured for the IP address of the hosting machine. Once you’ve done that, save and close the file.

Restart the Syncthing service with:

Accessing the Syncthing Web UI

Open a web browser and point it to http://SERVER:8384 (where SERVER is the IP address of the hosting machine. On the main page, you’ll be warned that you need to set a remote access password. Do that by clicking Settings (Figure 1). In the Settings pop-up, click the GUI tab and then set a username and password.

 Syncthing Settings window.

Figure 1: The Syncthing Settings button (bottom right).

Click Save when you’re finished. This will send you to the login page, where you’ll need to type the username and password you just set.

Connecting the Machines

Now that you have Syncthing up and running on both machines, it’s time to connect them. On one machine, go to the Syncthing Dashboard, click Action, and then click Show ID. You’ll be presented with a QR code and a long random string. Copy the string and then move to the other machine. On the second machine, in the Remote Devices section, click Add Device. In the Device ID section, paste the ID from the first machine, give the device a name and click Save.

Go to the Sharing tab and, in the Unshared Folders section, check the option Default Folder, then check the option for Auto Accept (Figure 2).

Screenshot: Adding a second node to Syncthing.

Figure 2: Adding a second node to Syncthing.

Click Save, then refresh the dashboard. The connected machine should now be listed as “Up to Date.”

Make sure you go through this process for both machines.

The default folder for Syncthing is ~/Sync. Any files or folders you add to that folder on one machine will automatically be synced with the other. You can test that by issuing the following command on one machine:


If you check on the second machine, you’ll find the testing file is in sync.

And that’s all there is to syncing machines with the help of Syncthing.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Unit.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.