How to Install Syncthing on Ubuntu 20.04 and Ubuntu 21.04

Syncthing is a free, open-source, peer-to-peer file synchronization application. Syncthing can sync files between devices on a local network or between remote devices over the Internet, with all data transmitted between multiple devices are encrypted with TLS. Whenever you create, modify or delete data on one peering node, the application will automatically replicate the changes to other servers. Another popular feature is Syncthing being cross-platform available on Windows, macOS, Linux, Android, Solaris, Darwin, and BSD making it possible to sync across multiple devices.

For users wanting to try out this great syncing software, at the end of this guide, you will know how to install Syncthing on Ubuntu 20.04 LTS. The same principle will work for the newer version Ubuntu 21.04 (Hirsute Hippo).

Pre-requisites

  • Recommended OS: (2x) Ubuntu 20.04 – optional (Ubuntu 21.04 and Linux Mint 20)
  • User account: A user account with sudo or root access.
  • Required packages: apt-transport-https, curl

Check and update your Ubuntu 20.04 operating system.

sudo apt update && sudo apt upgrade -y

By default, servers should come with (curl) installed, but you will check this along with installing the (apt-transport-https) package, which is required so the APT package manager can establish an HTTPS connection with this repository.

sudo apt install apt-transport-https curl -y

Install Syncthing using Official .Deb Respository

Syncthing is in the default Ubuntu repositories but is not as up to date as many would like. Instead, you will install the official source deb repository:

First, add the GPG key by executing the following command:

curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

You should get the (Ok) output as above in your Ubuntu terminal, and this means the GPG key has been imported successfully. Next, you will need to add the Syncthing repository by executing the following in your terminal:

echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now you can update your repositories and install Syncthing:

sudo apt update && sudo apt install syncthing -y

Confirm the installation by checking the version build:

syncthing --version
how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Configure Syncthing as a Systemd Service

Syncthing (.deb) package comes with the required (systemd) service file under the location (/lib/systemd/system). Under this directory, you will find the (syncthing@.service) file. The way Syncthing works is that you need to enter the username of the account between the (@) and the (.service), for example (syncthing@linuxcapable.service).

To kick start and enable Syncthing, you need to execute the following command.

sudo systemctl enable syncthing@username.service

To know if it was successful,l you should see the example below output with (Created symlink):

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now that the service is enabled on startup, you need to start it manually this one time by executing the following:

sudo systemctl start syncthing@username.service

Now, you should check the status by typing the following command:

sudo systemctl status syncthing@username.service
how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

To exit the status screen, press (Q) or (CTRL+C).

Note, your configuration files are under (/home/username/.config/syncthing/) and your default home folder is (/home/username/syncthing/). You can change the home folder later on if you choose. 

The main configuration file is located at (/home/username/.config/syncthing/config.xml) if you need to change or fix any settings such as changing the default 127.0.0.1 to an internal or external IP address.

Configure UFW Firewall

Syncthing will need to be allowed to use port (22000) to communicate with peers. If you are using UFW, then execute the following command to allow the port:

sudo ufw allow 22000/tcp

Install Syncthing Peers

To use Syncthing, you will need to install a second copy up to this point on another server or desktop. The most fantastic part about Syncthing is that you can install it not just on Linux but on multiple operating systems.

Note, if you are using Syncthing to back up to another platform that is not Linux, make sure to set (receive) only as the file permissions going to and from will cause issues.

First use and Configuration Syncthing WebUI

Syncthing listens to (127.0.0.1:8384) by default which you can access in your web browser. Type in the following in your Internet Explorer address bar:

http://127.0.0.1:8384

The first time you up the WebUI, you will notice a pop-up asking (Allow Anonymous Usage Reporting?). Select an option to proceed.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

After sorting out the usage reporting, you will be prompted with a (GUI Authentication: Set User and Password) notification. It is pretty important to secure your Syncthing service, so you should immediately hit (Settings) to proceed to the configuration page.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Next screen, select the (GUI) as shown below:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now, set up a (username) and (password). Also, this part you can set (HTTPS) for GUI use if you prefer. Once you have finished, press the (Save) button on the bottom right corner as shown:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now is the time to repeat all the above guide on a second peering operating system to move to the next part of the guide, which requires (two) Syncthing clients.

Syncing Files & Folders between Devices

Now you have installed 2 or more Syncthing clients on various devices and operating systems, and now you can set up syncing files or folders between the devices.

First off, in the WebUI on (peering node 1), you can click (Actions > Show ID) in the upper-right hand corner, and you will find the device ID, which is a long string of letters and numbers.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

You can also see the QT code, the device ID, and it is used for Syncthing on smartphones and tablets.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

The next step is copying the (Device Identification) which in the guide example is (CAL3FN4-R72LBTK-Q3ZFAEC-OUOAIEM-ZOJIMQ3-JHG5OCK-ZSJORVA-64552A3) from the WebUI interface of the node you want the files to sync from first which we have called (peering node 1) for this guide.

Next, you open the WebUI of the second peering device (peering node 2) and click (Add Remote Device) on the bottom right-hand corner. Past the Device ID, give the new device a name, and then click the (Save) button to proceed.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now back on (peering node 1), you will see (peering node 2) attempting to connect. If you do not see it, refresh your page and make sure UFW or a similar firewall does not block it. Click (Add Device) to continue:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Once you click to add the device, a new screen will appear on (peering node 1). Here, you can change the device’s default name, share files and directories automatically in the sharing panel, and more. Click (Save) to continue:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now both nodes are connected. You can now share a directory between the devices. For example, (peering node 1) has a folder you want to sync between itself and (peering node 2). The first click adds a folder on (peering node 1):

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

For the guide, the example used the (Downloads) directory to sync between the devices, and you can give the folder you want to sync to (peering node 2) a unique ID (name). For the guide, we named the ID (downloads-backup) and set the path. Do not click save. Click (Sharing) in the top row to continue:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now in the (Sharing) panel, click the remote device to share with. In our example below, it’s (peering node 2), then click save to continue.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now in (peering node 1), you will notice the folder scanning itself, which is fine, now switch back over the (peering node 2), and you will see a new pop up with (peering node 1) wanting to send the (Downloads) directory. Click add:

Now a new pop up will show on (peering node 2), here you can change your path if need be, along with adjusting any other options in the top pane. For now, click save to see the sync process begin:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Now it may take a minute or so, but the devices should start syncing, example below:

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Congratulations, you have successfully used Syncthing to sync two devices! Note if you see the following error (Failed to create folder marker: mkdir .stfolder: read-only file system), see the next step to fix permissions. Once corrected, restart the syncthing service, and it should start the process.

Configure Syncthing Permissions

Syncthing can sometimes run into issues with send and receive between remote nodes. With Linux systems, you can install the package (setfacl) by entering the following command:

sudo apt install acl

Then execute the following command with your username:

sudo setfacl -R -m u:username:rwx /folder/path/

If you constantly come into trouble with this as files change constantly, you can set a cron job up as below:

sudo crontab -e

Then add for syncing permissions every 5 minutes:

*/5 * * * * sudo setfacl -R -m u:username:rwx /folder/path/ -n

The second feature is to set (Ignore Permissions) in the (Advanced) options in Syncthing WebUI. This can fix issues as well but do note the above step with (setfacl) will most likely need to be done in conjunction with this feature.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Configure Send-Only & Receive-Only Folders

A great feature with Syncthing is that you can specify the peering nodes to send and receive. However, they also can send only and receive only, giving you ultimate flexibility. To do this, open up (Advanced) in the top panel of the folder currently being in sync and see (Folder Type) to change to receive, send or both.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Remember to click save.

Configure Syncthing Adjust Scan Intervals

If you do not require syncthing to watch for changes constantly and free up the CPU, you can disable (Watch for Changes) in the (Advanced) section in editing the syncing folder between devices.

Also, by default, a full re-scan is scheduled for each hour to sync changes hourly and be adjusted longer or shorter.

how to install syncthing on ubuntu 20.04 focal fossa and ubuntu 21.04 hirsute

Configure Nginx as a Reverse Proxy for Syncthing

Suppose you like to set up Syncthing to Nginx as a reverse proxy to access your server. The guide will show how to set up using port 80. Follow the example below:

First, install the custom Nginx PPA from Ondřej Surý, which is updated with better features:

Stable:

sudo add-apt-repository ppa:ondrej/nginx && sudo apt update -y

Mainline:

sudo add-apt-repository ppa:ondrej/nginx-mainline && sudo apt update -y

Next, install Nginx:

sudo apt install nginx-core nginx-common nginx nginx-full -y

You will need to create a virtual host file next. To do this, execute the following command:

sudo nano /etc/nginx/sites-available/syncthing.conf

Add the following code in the (syncthing.conf) file:

server {
  listen 80;
  server_name syncthing.example.com;

  access_log /var/log/nginx/syncthing.access.log;
  error_log /var/log/nginx/syncthing.error.log;
  location / {
    proxy_pass http://127.0.0.1:8384;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}

To save the file (CTRL+O) then (CTRL+X) to exit. Next, test your Nginx configuration by running the command:

sudo nginx -t

If everything is correct with no errors, you will get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

To finish off, reload or restart your Nginx service:

sudo systemctl restart nginx

From this point, you can access the Syncthing server using the URL http://syncthing.example.com.

Comments and Conclusion

You have learned how to install Syncthing between two peer nodes and set an active sync link between the devices in the guide. Overall, Syncthing has quite an extensive list of options, and the guide has only touched on some of the options it is truly capable of. The software is under constant development and is a good choice for users that need simple sync software with a friendly WebUI.

A note to users that have Linux and Windows devices, you cannot have the (Send and Receive) option on, as Windows does not save the file permissions of Linux, and if Windows sends a file back, it will cause sync issues with (permission) denied. Make sure you only send or receive if using in this set-up.

For more information, visit Syncthing documentation.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!