SaonBD | Paragraph logo

Subscribe to SaonBD | Paragraph

Get new posts delivered straight to your inbox.

All posts

Private File Synchronization Across Linux Servers with Syncthing

A practical guide to setting up encrypted, continuous server-to-client file synchronization across Linux infrastructure without central cloud dependencies.

Centralized cloud storage providers offer convenience, but they also introduce third-party risk, storage caps, and recurring fees. If you manage remote Linux servers, workstations, or offsite backup nodes, you often need continuous, low-latency file synchronization without surrendering data privacy.

Syncthing is an open-source, peer-to-peer file synchronization system that operates without central servers. Every transfer is encrypted end-to-end using TLS, and device communication relies on mutual cryptographic authentication. Combined with untrusted encrypted nodes and local systemd management, Syncthing provides robust private data replication across Linux infrastructure.

In this practical guide, we will walk through setting up Syncthing on Debian/Ubuntu, configuring systemd for automatic background management, pairing remote nodes securely, utilizing .stignore rules, and securing the web management GUI.


Why Self-Hosted Peer-to-Peer File Sync Beats Central Cloud Storage

Traditional cloud storage platforms store your files on centralized architecture. Even with encryption at rest, cloud providers retain control over metadata, authentication gateways, and server uptime.

Syncthing replaces central authority with a decentralized peer-to-peer network model:

  1. Zero Third-Party Data Exposure: Files travel directly between your machines over local networks or encrypted WAN tunnels.

  2. End-to-End Cryptography: Transits use TLS with perfect forward secrecy. Nodes authenticate each other using cryptographic Device IDs (derived from TLS certificates).

  3. Untrusted Node Encryption: You can synchronize data to a remote VPS while encrypting file contents and filenames on that target node, protecting data even if the remote node is compromised.

  4. Resilient Synchronization: Changes update continuously at the block level, ensuring minimal bandwidth usage for large, frequently updated files.


Step 1: Installing Syncthing and Configuring systemd

To ensure you receive security updates and stable releases, install Syncthing directly from the official upstream apt repository rather than distribution defaults.

1. Install the PGP Key and Repository

Run the following commands on your Debian/Ubuntu nodes:

# Install prerequisites
sudo apt update && sudo apt install -y curl apt-transport-https

# Add official Syncthing PGP release key
sudo mkdir -p /etc/apt/keyrings
sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg

# Add the stable repository to system sources
echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

# Update package lists and install Syncthing
sudo apt update
sudo apt install -y syncthing

2. Configure systemd Service for Non-Root User

Never run Syncthing as root. Syncthing includes a per-user systemd unit file (syncthing@.service) by default.

Enable and start Syncthing for your dedicated service user (e.g., sysadmin or your primary Linux user):

# Enable service to auto-start on boot for user 'sysadmin'
sudo systemctl enable syncthing@sysadmin.service

# Start the service
sudo systemctl start syncthing@sysadmin.service

# Verify status
sudo systemctl status syncthing@sysadmin.service

Step 2: Key Exchange and Device Pairing Across Remote Servers

Syncthing identifies every node by a unique Device ID—a cryptographic hash generated from its local TLS certificate.

1. Retrieve the Device ID

To locate the Device ID for a server via CLI:

syncthing --device-id

Alternatively, view it from the Syncthing Web GUI under Actions > Show ID.

2. Connect Remote Devices

To connect Server A and Server B:

  1. Copy the Device ID of Server B.

  2. On Server A's Web GUI, click Add Remote Device.

  3. Paste Server B's Device ID and assign a descriptive device name.

  4. On Server B, a prompt will appear requesting confirmation to accept the pairing request from Server A. Accept the connection.

Once paired, both nodes establish an encrypted TLS tunnel over default TCP port 22000.


Step 3: Setting Up Encrypted Folder Sync and Ignore Patterns

1. Creating Shared Folders

When sharing a folder between nodes:

  1. Select Add Folder in the GUI or edit configuration files.

  2. Specify the local folder path (e.g., /var/backups/app-data or /home/sysadmin/sync).

  3. Under the Sharing tab, check the paired remote devices you wish to sync with.

  4. Under Folder Type, select Send & Receive, Send Only (useful for primary application servers), or Receive Only (ideal for passive backup destinations).

2. Using Ignore Patterns (.stignore)

To keep temp files, build caches, and system sockets out of synchronization loops, create a .stignore file in the root of your shared folder directory:

// Ignore temporary files and OS metadata
(?d).DS_Store
(?d)thumbs.db
(?d).tmp.*

// Ignore build artifacts and cache directories
node_modules/
.cache/
*.tmp
*.log

The (?d) prefix allows Syncthing to delete these ignored files if the surrounding directory is deleted remotely.


Step 4: Hardening GUI Access with Reverse Proxies and TLS

By default, the Syncthing Web Interface listens strictly on 127.0.0.1:8384 for local security. Accessing this interface on a remote server requires either SSH port forwarding or a reverse proxy.

From your local machine, run:

ssh -L 8384:127.0.0.1:8384 user@your-remote-server-ip

Open http://127.0.0.1:8384 in your local browser to safely manage your remote Syncthing configuration.

Option B: Nginx Reverse Proxy with HTTPS Authentication

For permanent admin access, configure Nginx with SSL certificates from Let's Encrypt and HTTP basic authentication.

1. Install Nginx and Apache Utilities

sudo apt install -y nginx apache2-utils

2. Create Password Protection

sudo htpasswd -c /etc/nginx/.syncthing_htpasswd admin

3. Nginx Server Block Configuration

Add the following site configuration to /etc/nginx/sites-available/syncthing:

server {
    listen 80;
    server_name sync.yourdomain.com;
    return 312 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name sync.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/sync.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/sync.yourdomain.com/privkey.pem;

    auth_basic "Syncthing Private Access";
    auth_basic_user_file /etc/nginx/.syncthing_htpasswd;

    location / {
        proxy_pass http://127.0.0.1:8384/;
        proxy_set_header Host $host;
        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;

        # WebSockets support for live status updates
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 600s;
        proxy_send_timeout 600s;
    }
}

Enable the configuration and reload Nginx:

sudo ln -s /etc/nginx/sites-available/syncthing /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Summary & Next Steps

With Syncthing active under systemd, pair connections verified by TLS keys, and external Web GUI access secured behind authentication, your private Linux infrastructure now synchronizes files continuously and securely without third-party cloud dependence.

For complete automated server recovery, pair peer-to-peer file synchronization with deduplicated snapshot backups as detailed in our guide on Automated Server Backups with BorgBackup and Borgmatic on Linux.

Related guides

Join the discussion

Have a thought or a correction? Send it over — your message opens in your email app.

Subscribe

Get new posts delivered to your inbox.