UbuntuUbuntu Based

How To Install Syncthing on Ubuntu 24.04 LTS

Install Syncthing on Ubuntu 24.04

In today’s digital landscape, keeping files synchronized across multiple devices is more critical than ever. That’s where Syncthing comes in—a powerful, open-source file synchronization tool that ensures your data is always up-to-date across all your devices. It’s decentralized, secure, and versatile, making it an excellent choice for anyone looking to manage their files efficiently. This guide provides a detailed walkthrough on how to install Syncthing on Ubuntu 24.04 LTS, ensuring you can take full advantage of its capabilities.

Whether you’re a seasoned Linux user or just starting, this article will guide you through each step, from setting up the necessary prerequisites to configuring Syncthing for optimal performance. So, let’s dive in and get Syncthing up and running on your Ubuntu system.

What is Syncthing?

Syncthing is a continuous file synchronization program that operates on a peer-to-peer (P2P) network. Unlike cloud-based solutions like Nextcloud, Syncthing doesn’t rely on central servers. Instead, it allows you to synchronize files between multiple devices in real-time, ensuring your data is consistent across all your machines.

Security is a primary focus; Syncthing encrypts all communication using TLS, protecting your data from unauthorized access. You have complete control over where your data is stored and with whom it is shared, making it a safe and private solution for file synchronization. Syncthing is available on various platforms, including Linux, Windows, macOS, and Android. It offers a flexible solution for maintaining consistent files across different operating systems.

Syncthing stands out as a robust alternative to other synchronization tools like Resilio Sync (formerly BitTorrent Sync). Its open-source nature and decentralized approach provide enhanced control and security over your data.

Prerequisites

Before we begin the installation process, make sure you have the following prerequisites in place:

  • An Ubuntu 24.04 LTS system.
  • A user account with sudo privileges.
  • A stable internet connection.

It’s also a good idea to update your system to ensure you have the latest packages. Open your terminal and run the following commands:

sudo apt update && sudo apt upgrade -y

This command updates the package lists and upgrades any outdated packages on your system, setting the stage for a smooth Syncthing installation.

Adding the Syncthing Repository

Syncthing is not typically included in the default Ubuntu repositories. This means we need to add the official Syncthing repository to your system’s APT sources. Adding the repository ensures that you receive the latest versions and updates directly from the Syncthing developers.

First, install the necessary dependencies required to add and manage external repositories:

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

These packages provide the tools needed to handle GPG keys and access repositories over HTTPS. Next, download and add the Syncthing GPG key to your system. This key verifies the authenticity of the packages you’ll be installing:

curl -fsSL https://syncthing.net/release-key.txt | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/syncthing.gpg

Now, add the Syncthing repository to your APT sources list:

echo "deb https://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list

Finally, update the repository index to include the new Syncthing repository:

sudo apt update

With the repository added and updated, your system is now ready to install Syncthing.

Installing Syncthing

With the Syncthing repository successfully added, the next step is to install Syncthing itself. Run the following command in your terminal:

sudo apt install syncthing

This command fetches and installs Syncthing along with any required dependencies. Once the installation is complete, verify it by checking the Syncthing version:

syncthing --version

The output should display the installed Syncthing version, confirming that the installation was successfu. For example:

syncthing v1.27.3 "Gold Grasshopper" (go1.21.6 linux-amd64) [email protected] 2024-01-15 03:45:19 UTC [noupgrade]

Configuring Syncthing as a Systemd Service

To ensure Syncthing runs reliably and starts automatically on boot, it’s best to configure it as a systemd service. Systemd is the system and service manager for Linux, providing a way to manage background processes.

Enable Syncthing to start on boot using the following command. Make sure to replace username with your actual username:

sudo systemctl enable syncthing@username.service

Start the Syncthing service:

sudo systemctl start syncthing@username.service

Check the status of the Syncthing service to ensure it is running correctly:

sudo systemctl status syncthing@username.service

The output should indicate that the service is active and running. If there are any errors, check the systemd logs for more details. Syncthing’s configuration files are stored in /home/username/.config/syncthing/, and the default synchronization folder is /home/username/Sync. Make sure these directories exist and are accessible by your user.

Accessing the Syncthing Web Interface

Syncthing provides a web interface for managing your synchronization settings. By default, the web interface is accessible only from the local machine. To access it, open your web browser and navigate to http://localhost:8384 or http://127.0.0.1:8384.

Install Syncthing on Ubuntu 24.04 LTS

If you want to access the web interface from another device on your network, you need to modify the Syncthing configuration file. Open the config.xml file located in ~/.config/syncthing/ using a text editor like nano:

nano ~/.config/syncthing/config.xml

Locate the <address> tag and change the address from 127.0.0.1:8384 to 0.0.0.0:8384. This allows Syncthing to listen on all network interfaces.

<gui enabled="true" tls="false" debugging="false">
  <address>0.0.0.0:8384</address>
  ...
 </gui>

For enhanced security, set up user authentication for Syncthing by adding a username and password within the <gui> section of the configuration file:

<gui enabled="true" tls="false" debugging="false">
  <address>0.0.0.0:8384</address>
  <user>your_username</user>
  <password>your_hashed_password</password>
  ...</gui>

Replace your_username with your desired username. Generate a hashed password using Syncthing’s built-in tool:

syncthing generate --gui-password=your_passwor

Copy the generated hashed password and paste it into the <password> field in the config.xml file. Save the changes and restart the Syncthing service:

sudo systemctl restart syncthing@username.servic

Now, you can access the Syncthing web interface from any device on your network by navigating to http://your_ubuntu_ip:8384. You’ll be prompted to enter the username and password you configured.

Configuring Syncthing

Once you access the Syncthing web interface, you can begin configuring your synchronization settings. The initial setup involves adding devices and sharing folders.

Adding a Device

To synchronize files between two devices, you need to add each device to the other’s Syncthing configuration. Here’s how to do it:

  1. Obtain the Device ID: On the first device, find the Device ID in the web interface (usually displayed at the top or in the “Settings” menu). The Device ID is a long string of characters.
  2. Add the Device: On the second device, click the “Add Device” button in the web interface. Enter the Device ID of the first device in the “Device ID” field. Give the device a name in the “Device Name” field.
  3. Advanced Settings: In the “Advanced” tab, you can specify the address for the device. If the devices are on the same local network, Syncthing should automatically discover them. If they are on different networks, you may need to enter the remote device’s IP address and port (e.g., tcp://<peer>:22000).
  4. Save the Configuration: Click “Save” to add the device.
  5. Accept the Connection: On the first device, you will receive a message asking if you want to connect to the new device. Accept the connection to finish linking the devices.

Sharing a Folder

After adding the devices, you can share folders between them:

  1. Add a Folder: On the device where the folder is located, click the “Add Folder” button in the web interface.
  2. Specify the Folder Path: Enter the path to the folder you want to synchronize in the “Folder Path” field. If the folder does not exist, Syncthing can create it for you.
  3. Sharing Tab: Switch to the “Sharing” tab and select the device you want to share the folder with.
  4. Save the Configuration: Click “Save” to share the folder.
  5. Accept the Share: On the other device, you will receive a message asking if you want to add the shared folder to your system. Click “Add” and specify the path where you want the synchronized folder to be located.

Now the two devices are syncing files. You can create new files in the shared directory on one machine and verify that they appear on the other.

cd ~/Sync/
touch {1..20}.txt
ls -al

Addressing the “Failed to Connect” Error

If you encounter a “Failed to connect” error, it typically indicates a network connectivity issue between the devices. Here are a few things to check:

  • Firewall Settings: Ensure that your firewall is not blocking Syncthing traffic (see the next section on Firewall Configuration).
  • Network Connectivity: Verify that both devices are connected to the internet or the same local network.
  • Address Configuration: Double-check the address configuration in the “Advanced” tab of the device settings. If the devices are on different networks, you may need to specify the remote device’s IP address and port.
  • Relay Servers: If direct connections are not possible, Syncthing will attempt to use relay servers to transfer files. However, relay servers can be slower. To disable relay servers, edit the device settings and change the address from “dynamic” to tcp://ip-address:22000, using your real IP address.

Firewall Configuration

Configuring your firewall is crucial to allow Syncthing traffic. Ubuntu uses ufw (Uncomplicated Firewall) as its default firewall. To allow Syncthing traffic, run the following commands:

sudo ufw allow 22000/tcp
sudo ufw allow 22000/udp
sudo ufw allow 21027/udp
sudo ufw enable
sudo ufw status

These commands open the necessary ports for Syncthing to communicate with other devices. Port 22000 is used for TCP and UDP connections, while port 21027 is used for local discovery. After running these commands, your firewall should be properly configured to allow Syncthing traffic.

Installing Syncthing Tray (Optional)

Syncthing Tray is a useful tool for managing Syncthing on desktop environments. It provides a system tray icon that allows you to quickly access the Syncthing web interface and monitor synchronization status.

To install Syncthing Tray on Windows, follow these steps:

  1. Download Syncthing Tray: Visit the Releases page of the Syncthing Tray GitHub repository.
  2. Extract the Archive: Extract the downloaded archive to a directory of your choice.
  3. Run Syncthing Tray: Launch Syncthing Tray by opening the executable file.
  4. Windows Security Alert: If a Windows Security Alert box appears, select both the “Private” and “Public” networks options, and then click “Allow access” to allow incoming connections through the firewal.
  5. Windows Defender SmartScreen: If the Windows Defender SmartScreen warning appears, select “More info” and click “Run anyway”.

Syncthing Tray will now run in the system tray, providing easy access to Syncthing’s web interface and status information.

Troubleshooting Common Issues

Even with careful setup, you might encounter some issues while using Syncthing. Here are some common problems and their solutions:

  • Slow Synchronization: Slow synchronization can be caused by several factors. First, verify that you are not connected via a relay server. In the “Remote Devices” list, check that you see “Address: <some address>” and not “Relay: <some address>“. If you are using a relay, double-check your firewall settings to enable direct connections. Also, ensure that the network connection is stable and that there are no bandwidth limitations.
  • High CPU Usage: Syncthing can use a lot of CPU when scanning or syncing files. This is normal, especially when new or changed files are detected, or when Syncthing starts for the first time. However, if CPU usage remains consistently high, you can limit the amount of CPU used by setting the environment variable GOMAXPROCS to the maximum number of CPU cores Syncthing should use. For example, GOMAXPROCS=2 on a machine with four cores will limit Syncthing to no more than half the system’s CPU power.
  • “Failed to Connect” Errors: As mentioned earlier, this error typically indicates a network connectivity issue. Double-check your firewall settings, network configuration, and device addresses. If the devices are on different networks, you may need to configure port forwarding on your router.
  • Conflicts: Syncthing may create conflict files if the same file is modified on two devices simultaneously. These files have a .sync-conflict extension. To resolve conflicts, review the conflicting files and merge the changes manually. Syncthing also provides file versioning, allowing you to revert to previous versions of files if needed.
  • Database Errors: If you encounter database errors, it may be due to faulty hardware or other issues. Syncthing will log these errors and exit. To resolve this, delete the database folder inside Syncthing’s data directory and restart Syncthing. Syncthing will then perform a full re-hashing of all shared folders.

Congratulations! You have successfully installed Syncthing. Thanks for using this tutorial for installing the Syncthing on Ubuntu 24.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official Syncthing website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button