Syncthing is an open-source tool used for synchronizing files between two or more computers on a network. It uses peer-to-peer architecture and exchanges your data directly between your devices. All data transmitted between multiple devices are encrypted with TLS. Whenever you create, modify, or delete any data on one Syncthing machine it will automatically be replicated to other servers. It can install in all major operating systems including, Linux, Windows, Mac OS X, etc.

In this guide, we will show you how to install and set up Syncthing server on Ubuntu 20.04.

Prerequisites

  • Two servers running Ubuntu 20.04.
  • A valid domain name pointed with your server IP.
  • A root password is configured on both servers.

Getting Started

First, update the system packages to the updated version by running the following command:

apt-get update -y

Once all the packages are updated, you can proceed to the next step.

Install Syncthing Server on Both Server

By default, the Syncthing package is not included in the Ubuntu 20.04 default repository. So you will need to add the Syncthing repository to the APT.

First, install all the required dependencies on both servers with the following command:

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

Next, download and add the release key with the following command:

curl -s https://syncthing.net/release-key.txt | apt-key add -

Next, 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

Next, update the repository and install the Syncthing server with the following command:

apt-get update -y

apt-get install syncthing -y

Once the installation is completed, verify the version of Syncthing with the following command:

syncthing --version

You should get the following output:

syncthing v1.18.0 "Fermium Flea" (go1.16.5 linux-amd64) [email protected] 2021-06-21 20:53:50 UTC [noupgrade]

At this point, Syncthing is installed on both server. You can now proceed to the next step.

Create a Systemd Unit File on Both Server

Next, you will need to create a systemd unit file for managing the Syncthing service. You can create it on both servers with the following command:

nano /etc/systemd/system/[email protected]

Add the following lines:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target

[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -gui-address="0.0.0.0:8384" -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4

[Install]
WantedBy=multi-user.target

Save and close the file when you are finished. Then, reload the systemd daemon to apply the configuration:

systemctl daemon-reload

Next, start the Syncthing service with the following command:

systemctl start [email protected]

To verify the status of the Syncthing service, run the following command:

systemctl status [email protected]

You should see the following output:

? [email protected] - Syncthing - Open Source Continuous File Synchronization for root
     Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-09 04:40:12 UTC; 5s ago
       Docs: man:syncthing(1)
   Main PID: 2878 (syncthing)
      Tasks: 14 (limit: 2353)
     Memory: 44.2M
     CGroup: /system.slice/system-syncthing.slice/[email protected]
             ??2878 /usr/bin/syncthing -no-browser -gui-address=0.0.0.0:8384 -no-restart -logflags=0
             ??2889 /usr/bin/syncthing -no-browser -gui-address=0.0.0.0:8384 -no-restart -logflags=0

Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: QUIC listener ([::]:22000) starting
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: Loading HTTPS certificate: open /root/.config/syncthing/https-cert.pem: no such file or d>
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: Creating new HTTPS certificate
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: Completed initial scan of sendreceive folder "Default Folder" (default)
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: GUI and API listening on [::]:8384
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: My name is "node1"
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] WARNING: Syncthing should not run as a privileged or system user. Please consider using a norma>
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: quic://0.0.0.0:22000 detected NAT type: Not behind a NAT
Jul 09 04:40:14 node1 syncthing[2878]: [WPOF6] INFO: quic://0.0.0.0:22000 resolved external address quic://45.58.35.6:22000 (via stun.syncthin>

At this point, Syncthing service is started and listening on port 8384. You can check it with the following command:

ss -antpl | grep 8384

You should see the following output:

LISTEN    0         4096                     *:8384                   *:*        users:(("syncthing",pid=2889,fd=12))    

Access Syncthing Web Interface

Next, open your web browser and access the Syncthing web interface using the URLs http://first-server-ip:8384 and http://first-server-ip:8384.

You should see the following screen:

<img alt="Syncthing admin interface" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p1.png60f5916dabb66.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="402" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on the Settings to define admin user and password as shown below:

<img alt="Set a password" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p2.png60f5916e16aa6.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="446" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide your username, password and click on Save button to apply the changes. You will be redirected to the Syncthing login page:

<img alt="sign-in" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p3.png60f5916e641db.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="263" loading="lazy" src="data:image/svg xml,” width=”449″>

Provide your admin username, password and click on Sign in button. You should see the following screen:

<img alt="Folders" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p4.png60f5916ecf3c9.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="399" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, you will need to add the device ID of each server to another server in order to sync files between both servers. To do so, click on Actions > Show ID button on both servers. You should see the following screen:

<img alt="Device identification" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p5.png60f5916f56118.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="484" loading="lazy" src="data:image/svg xml,” width=”750″>

<img alt="identify node 2" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p6.png60f5916fd0f6c.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="484" loading="lazy" src="data:image/svg xml,” width=”750″>

On the first server, click on Add Remote Device. You should see the following screen:

<img alt="Add a device" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p7.png60f59170685b6.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="390" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide the device ID of the second server and click on the Save button.Advertisement

On the second server, click on Add Remote Device. You should see the following screen:

<img alt="Device ID" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p8.png60f59170d447d.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="389" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide the device ID of the first server and click on the Save button. You should see the following screen:

<img alt="Folders and Devices" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p9.png60f591714cfac.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="380" loading="lazy" src="data:image/svg xml,” width=”750″>

Now, you will need to add and share the folder that you want to sync with the second server. Click on the Add Folder button. You should see the following screen:

<img alt="Add a folder" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p11.png60f59171cd808.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="514" loading="lazy" src="data:image/svg xml,” width=”750″>

Provide your folder label, folder path, and click on the Sharing tab. You should see the following screen:

<img alt="Folder sharing" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p13.png60f59172477fe.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="263" loading="lazy" src="data:image/svg xml,” width=”750″>

Tick to the second server and click on the Save button. You should see the following screen:

<img alt="Folders and devices in Syncthing" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p14.png60f59172c46e5.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="398" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, go to the second server and click on Rescan All button. You should see the following screen:

<img alt="Rescan all" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p15.png60f591733d2a3.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="383" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on Add to add the Backup folder shared on the first server. You should see the following screen:

<img alt="Syncing folders" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/p16.png60f59173b6539.jpg" ezimgfmt="rs rscb4 src ng ngcb4" height="404" loading="lazy" src="data:image/svg xml,” width=”750″>

Now, whenever you create or modify any files on the Backup folder on the first server they will be synchronized automatically to the second server.

Configure Nginx as a Reverse Proxy for Syncthing

You can also set up Nginx as a reverse proxy to access the Syncthing server through port 80.

First, install the Nginx server with the following command:

apt-get install nginx -y

Next, create an Nginx virtual host configuration file with the following command:

nano /etc/nginx/conf.d/syncthing.conf

Add the following lines:

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;
  }
}

Save and close the file then verify the Nginx for any syntax error with the following command:

nginx -t

You should 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

Next, reload the Nginx to apply the changes.

systemctl reload nginx

You can also check the status of the Nginx using the following command:

systemctl status nginx

You should see the following output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-09 05:01:36 UTC; 21s ago
       Docs: man:nginx(8)
   Main PID: 3394 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 6.2M
     CGroup: /system.slice/nginx.service
             ??3394 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??3395 nginx: worker process

Jul 09 05:01:36 node1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 09 05:01:36 node1 systemd[1]: Started A high performance web server and a reverse proxy server.

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

Conclusion

Congratulations! you have successfully installed and configured Syncthing on two Ubuntu 20.04 servers and set up synchronization between both servers. I hope this tutorial will help you to backup your server.