Syncthing is a secure and open source file synchronisation program for multiple platforms, such as Windows, macOS, Linux, Android, Solaris, Darwin and BSD. It is a decentralised and peer-to-peer (P2P) file synchronisation tool that allows you to synchronise files between devices on a local network or between remote devices over the internet.

In this tutorial, I will show you how to install Syncthing on a Ubuntu 22.04 servers. You will then learn how to establish a connection between Syncthing instances, set up the synchronisation of directories and check the synchronisation.

Prerequisites

To get started with this tutorial, you must have the following:

  • Two Ubuntu 22.04 Machines – In this example, we’ll use two Ubuntu servers server1 and server2.
  • A non-root user with administrator privileges.

Adding Syncthing Repository

Syncthing can be installed in multiple ways, you can install it manually via binary file, or install it via APT for Ubuntu. In this example, you will install syncthing via APT by adding the official repository to both Ubuntu machines.

To start, execute the following command to install some basic packages to your Ubuntu system.

sudo apt install gnupg2 curl apt-transport-https -y

<img alt="install basic packages" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/1-install-basic-packages.png6573499160789.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="270" loading="lazy" src="data:image/svg xml,” width=”671″>

Now, add the syncthing GPG key and repository to your both Ubuntu systems. In this case, you will install the latest release of Syncthing via the APT repository.

curl -fsSL https://syncthing.net/release-key.txt | 

sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/syncthing.gpg

echo "deb https://apt.syncthing.net/ syncthing release" |

sudo tee /etc/apt/sources.list.d/syncthing.list

<img alt="add repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/2-addsyncthing-repo.png657349918d441.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="167" loading="lazy" src="data:image/svg xml,” width=”711″>

Then, update and refresh your Ubuntu repository using the following command.

sudo apt update

When you see the syncthing repository is available, you’re ready to go.

<img alt="refresh repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/3-refresh-repo.png65734991b8690.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="232" loading="lazy" src="data:image/svg xml,” width=”705″>

Installing Syncthing

Now that you’ve added a syncthing repository to both Ubuntu machines, the next step you will install it on both machines and configure it to run as a systemd service. Also, ensure you have a non-root user on both machines to run syncthing.

To install syncthing, run the following apt command. Type y and press ENTER to proceed with the installation.

sudo apt install syncthing

<img alt="install syncthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/4-install-syncthing.png65734991cf8da.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="206" loading="lazy" src="data:image/svg xml,” width=”647″>

After the installation is complete, verify the syncthing version like this:

syncthing --version

syncthing -h

In the following output, you should see syncthing 1.26 is installed.

<img alt="check syncthing version" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/5-check-syncthing.png657349920a146.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="472" loading="lazy" src="data:image/svg xml,” width=”750″>

Now that you’ve installed syncthing, you should start it as per-user. In this example, we’ll be using user alice on the server1, and user bob on the server2.

Log in to your user using the command below.

su - alice

Then, start and enable the syncthing service for user alice using the command like this:

sudo systemctl start [email protected]

sudo systemctl enable [email protected]

Be sure to input your password to get the root privileges when asked:

<img alt="start enable syncthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/6-start-enable-syncthing.png657349923dae9.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="230" loading="lazy" src="data:image/svg xml,” width=”712″>

Now verify the syncthing service to ensure that the service is running via the command below.

sudo systemctl status [email protected]

You should see the syncthing service for user alice is running. Also, ensure the syncthing service on bot your servers is running.

<img alt="check synchthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/7-syncthing-run.png657349926a786.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="241" loading="lazy" src="data:image/svg xml,” width=”750″>

Setting Up Firewall

In this guide, you will enable the firewall on both Ubuntu machines. On Ubuntu, you can use UFW (Uncomplicated Firewall), and by default, syncthing also provides a UFW application profile, so you can easily enable it.

Run the command below to add the syncthing and syncthing-gui profiles to UFW.

sudo ufw allow syncthing

sudo ufw allow syncthing-gui

Now add the OpenSSH profile, then start and enable UFW using the below command. Type y to confirm with the operation.

sudo ufw allow OpenSSH

sudo ufw enable

Once complete, you will see the following output.

<img alt="setup ufw" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/8-enable-ufw.png657349929600f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="241" loading="lazy" src="data:image/svg xml,” width=”733″>

Next, verify the list-enabled rules and profiles on UFW using the command below.

sudo ufw status verbose

Ensure both syncthing and syncthing-gui are added to UFW.

<img alt="verify ufw" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/9-synchting-ufw.png65734992c78b5.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="364" loading="lazy" src="data:image/svg xml,” width=”581″>

Initializing Syncthing Instances

Now that you’ve installed Syncthing and configured UFW, you’re ready to start initializing your installation. In this step, you will set up syncthing to run on a local IP address with HTTPS enabled, and you will set up user authentication for syncthing.

By default, syncthing is running on localhost. If you want to run syncthing on a local IP address, modify the syncthing configuration ~/.config/syncthing/conf.xml file.

Open the ~/.config/syncthing/conf.xml file using the nano editor command below.

nano ~/.config/syncthing/conf.xml file

Within the section, change the ‘tls‘ value to ‘true‘ and change the default localhost to your local IP address.

    

       
192.168.5.30:8384


        GENERATED-API-KEY

        default

   

Save and close the file when finished.

Now run the following command to restart the syncthing service.

sudo systemctl restart [email protected]

Open your web browser and visit syncthing via server IP address and port 8384 (i.e: https://192.168.5.30:8384/).

If your installation is successful, you should get the following page:

Click Settings to set up syncthing.

<img alt="setup syncthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/10-setup-admin-gui.png657349932174b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="339" loading="lazy" src="data:image/svg xml,” width=”750″>

Within the GUI tab, change your user and password, then click Save.

<img alt="setup admin user" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/11-setup-auth.png65734993542d4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="411" loading="lazy" src="data:image/svg xml,” width=”750″>

After the new password is configured, you will be prompted with syncthing authentication.

Input your username and password, then click Log In.

<img alt="login syncthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/12-authenticate.png6573499390554.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="231" loading="lazy" src="data:image/svg xml,” width=”750″>

If you have the proper user and password, you should get the syncthing dashboard like the following:

<img alt="syncthing dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/13-syncthing-running.png65734993d6789.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="336" loading="lazy" src="data:image/svg xml,” width=”750″>

Below is the syncthing dashboard of server2 after the user and password are configured.

<img alt="syncthing dashboard server2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/16-server2-dashboard.png6573499466de1.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="338" loading="lazy" src="data:image/svg xml,” width=”750″>

Connecting Two Syncthing Instances

After configuring Synthing on both Ubuntu machines, you will connect, so you can sync files between those machines. To do that, you must verify both machines via GUI.

On the server1, click the Action button at the top right, then select Show ID.

<img alt="show id" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/14-show-id.png65734994903b7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="248" loading="lazy" src="data:image/svg xml,” width=”277″>

Copy the device ID of the server1. The syncthing device ID is generated automatically during stat. Furthermore, you can also use QRcode to connect between syncthing instances, for example between computers and Android phones.

<img alt="device id server1" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/15-device-id.png65734994de260.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="472" loading="lazy" src="data:image/svg xml,” width=”750″>

Move to server2, and click Add Remote Device to add a new syncthing instance.

<img alt="add remote device" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/17-add-remote-device.png6573499506705.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="163" loading="lazy" src="data:image/svg xml,” width=”685″>

Paste the device ID of server1, input the name as server1, and then click Save to confirm.

<img alt="add server1" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/18-add-device.png65734995361c0.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="426" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, move back to the server1 dashboard and the information about server2 wants to connect to. Click Add Device to add the server1.

<img alt="confirm server2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/19-confirm-device-server1.png657349956c104.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="186" loading="lazy" src="data:image/svg xml,” width=”750″>

Now, the new pop-up will come up, verify the device ID of server2, then click Save.

<img alt="confirm server2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/20-confirm-server2.png657349959c75e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="328" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, go to the syncthing dashboard and move to the Remote Devices section. If the process is successful, you should see the server2 with status connected.

<img alt="server1 connected to server2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/21-server1-connected.png65734995b5c2c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="232" loading="lazy" src="data:image/svg xml,” width=”687″>

On the other hand, when you check on the server2, you should see that server1 is connected.

<img alt="server2 connected to server1" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/22-server2-connected.png65734995de1ca.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="216" loading="lazy" src="data:image/svg xml,” width=”707″>

Synchronizing Directory with Syncthing

At this point, both server1 and server2 are connected via syncthing. Now, you will learn how to share a directory/folder and sync files between syncthing instances.

On the server1 dashboard, take a look at the Folders section, and you will find the Default Folder with path directory /home/alice/Sync and status Unshared.

Click Edit to share the Default Folder.

<img alt="edit folder" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/23-edit-folder.png657349962ccc6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="549" loading="lazy" src="data:image/svg xml,” width=”678″>

  • Move to the Sharing tab, and you will see the list of connected syncthing instances. Select server2 to share the Default Folder with the syncthing instance server2.
  • Move to the File Versioning tab, select the File Versioning method that you want to use, and then input how much versioning you want to keep.

Click Save to apply your modification.

Lastly, move to the server2 dashboard, and you will get the notification message that server1 wants to share the Default Folder. Click Share to confirm.

Once the process is finished, you should see the Default Folder is shared.

On the server1 Default Folder section, you should see the Shared With section with the value server2.

On the server2, you should see the Default Folder and Shared With section to server1.

File Synchronization between Synchthing Instances

Now that you’ve configured the shared directory via Syncthing, let’s verify it by creating new files from server1 and verifying the list files on server2 to ensure the synchronization is working.

On the server1, go to the Sync directory and create new files using the following command.

cd ~/Sync/

touch {1..20}.txt

<img alt="create files server1" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/28-create-files-server1.png6573499649326.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="190" loading="lazy" src="data:image/svg xml,” width=”750″>

Move to server2, go to the Sync directory, and check the list of files in that directory.

cd ~/Sync/

ls -ah

If you see multiple .txt files on the Sync directory, you’ve accomplished the syncthing installation without any problem.

<img alt="check files server2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/12/echo/29-synced-server2.png6573499665e43.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="91" loading="lazy" src="data:image/svg xml,” width=”750″>

From here, you can create and share a new directory between syncthing instances. , you can also add new instances.

Conclusion

Congratulations! You’ve completed the installation of Syncthing on Ubuntu 22.04 servers. You’ve also learned how to secure syncthing with UFW (Uncomplicated Firewall), connect between syncthing instances, set up shared folders, and verify the synchronization between shared directories.

Furthermore, you can new devices to your current syncthing installation and set up shared folders, so you can access files from multiple devices.