EN

Linux and networking

Sync Your Files with rclone

Sync your files with rclone to S3 storage or an SFTP server: client-side encryption, archives, systemd scheduling and a restore test.

7 min read, updated on 18 November 2026

On this page

Your values

Enter them once and the commands in this guide update.

This guide explains how to use rclone to send the files of your VPS or dedicated server to S3-compatible storage or another service, such as an SFTP server. Your data will be encrypted before it leaves, the sync will be scheduled, and you will check that you know how to get it back.

Prerequisites

  • A server running Debian 12 or 13, or Ubuntu 22.04 or 24.04, with sudo access
  • An S3 bucket with an access key and a secret key, or an SFTP server
  • A system clock set to the correct time: see our guide Configure NTP
  • A place off the server to keep the rclone configuration and the passwords

No inbound port needs to be opened. The server must be able to connect out to port 443 for S3, or to the remote server's SSH port for SFTP.

Install rclone

The project advises against distribution packages, which are often outdated. Install the official package. At the time of writing, the current version is 1.76.0: see the download page and adjust RCLONE_VERSION if needed.

Terminal
RCLONE_VERSION="v1.76.0"
ARCH="$(dpkg --print-architecture)"
FILE="rclone-${RCLONE_VERSION}-linux-${ARCH}.deb"
cd /tmp
curl -fsSLO "https://downloads.rclone.org/${RCLONE_VERSION}/${FILE}"
curl -fsSLO "https://downloads.rclone.org/${RCLONE_VERSION}/SHA256SUMS"
sha256sum --check --ignore-missing SHA256SUMS
sudo apt install -y "./${FILE}"
rclone version

The verification must show OK for the package. A warning about improperly formatted lines is normal, because the file also contains its signature.

Configure S3 storage

The examples use HostMyServers Object Storage, which is S3-compatible and whose endpoint published on that page is https://s3.lyn.io.hostmyservers.net. The bucket is called mes-sauvegardes: adapt this name.

  1. Create the configuration file, readable by root only:

    Terminal
    sudo install -d -m 700 /root/.config /root/.config/rclone
    sudo install -m 600 /dev/null /root/.config/rclone/rclone.conf
    sudo nano /root/.config/rclone/rclone.conf
  2. Add this block:

    Configuration
    [hms-s3]
    type = s3
    provider = Other
    access_key_id = YOUR_ACCESS_KEY
    secret_access_key = YOUR_SECRET_KEY
    endpoint = https://s3.lyn.io.hostmyservers.net
    acl = private

    For another S3-compatible provider, change endpoint and add region = YOUR_REGION if it requires one.

  3. Test access and create the bucket if it does not exist yet:

    Terminal
    sudo rclone lsd hms-s3:
    sudo rclone mkdir hms-s3:mes-sauvegardes

Add encryption

The crypt type encrypts the content as well as file and folder names before upload. It works as a layer on top of the storage.

  1. Generate two secrets and create the encrypted storage hms-crypt:

    Terminal
    CRYPT_PASS="$(openssl rand -hex 32)"
    CRYPT_SALT="$(openssl rand -hex 32)"
    sudo rclone config create hms-crypt crypt remote=hms-s3:mes-sauvegardes/crypt filename_encryption=standard directory_name_encryption=true password="$CRYPT_PASS" password2="$CRYPT_SALT" --obscure
    printf 'password: %s\npassword2: %s\n' "$CRYPT_PASS" "$CRYPT_SALT"
    unset CRYPT_PASS CRYPT_SALT
  2. Copy the two displayed values to your password manager, then also back up the rclone.conf file off the server:

    Terminal
    sudo cat /root/.config/rclone/rclone.conf
  3. Check that names are really encrypted remotely:

    Terminal
    echo "rclone test" | sudo tee /tmp/rclone-test.txt > /dev/null
    sudo rclone copy /tmp/rclone-test.txt hms-crypt:test
    sudo rclone ls hms-crypt:test
    sudo rclone ls hms-s3:mes-sauvegardes/crypt
    sudo rclone purge hms-crypt:test

    The first listing shows rclone-test.txt, the second an unreadable name.

With standard encryption, limit file names to about 143 characters to avoid any problem.

Choose the right command

Command Effect Risk
rclone copy Copies new or modified files, without deleting anything Low
rclone sync Makes the destination identical to the source, deletions included High
rclone move Copies then deletes from the source High
rclone check Compares source and destination None
rclone cryptcheck Compares local files with encrypted storage None

Run a first sync

The examples sync /srv/data. Replace this path with your folder.

  1. Create the exclusion list:

    Terminal
    sudo nano /etc/rclone-sync.filter
    Text
    - *.tmp
    - .cache/**
    - node_modules/**
  2. Always simulate before syncing:

    Terminal
    sudo rclone sync /srv/data hms-crypt:current --filter-from /etc/rclone-sync.filter --dry-run --verbose
  3. If the list looks right, start the upload:

    Terminal
    sudo rclone sync /srv/data hms-crypt:current --filter-from /etc/rclone-sync.filter --progress
  4. Check the result:

    Terminal
    sudo rclone cryptcheck /srv/data hms-crypt:current --one-way --filter-from /etc/rclone-sync.filter

Test the restore

Do this test now, then regularly. A remote copy is only useful if you know how to read it back and decrypt it.

  1. Restore everything into a temporary folder and compare:

    Terminal
    sudo rm -rf /var/tmp/rclone-restore
    sudo rclone copy hms-crypt:current /var/tmp/rclone-restore --progress
    sudo diff -r /srv/data /var/tmp/rclone-restore | head -n 20

    Only files that are excluded or were modified since the sync should appear.

  2. Also restore a single file, adjusting its path:

    Terminal
    sudo rclone copyto hms-crypt:current/dossier/fichier.txt /var/tmp/fichier-restaure.txt
  3. Test recovery on another machine: install rclone, put rclone.conf back from your external copy into /root/.config/rclone/, then run the same rclone copy command. This test proves that your copy of the configuration is complete.

  4. Then delete the test files:

    Terminal
    sudo rm -rf /var/tmp/rclone-restore /var/tmp/fichier-restaure.txt

Schedule the sync

The following script moves each replaced or deleted file into a dated archive folder, and keeps the last 30.

  1. Create the script:

    Terminal
    sudo nano /usr/local/sbin/rclone-sync.sh
    Terminal
    #!/bin/bash
    set -euo pipefail
    
    SOURCE="/srv/data"
    REMOTE="hms-crypt:"
    KEEP_ARCHIVES=30
    STAMP="$(date +%F_%H%M%S)"
    
    rclone sync "$SOURCE" "${REMOTE}current" \
      --backup-dir "${REMOTE}archive/$STAMP" \
      --filter-from /etc/rclone-sync.filter \
      --max-delete 1000 \
      --fast-list \
      --log-level INFO \
      --stats 5m \
      --stats-one-line
    
    { rclone lsf --dirs-only "${REMOTE}archive" 2>/dev/null || true; } |
      sort | head -n -"$KEEP_ARCHIVES" |
      while IFS= read -r dir; do
        rclone purge "${REMOTE}archive/${dir%/}"
      done

    --max-delete 1000 aborts the operation if more than 1,000 files would be removed. This limit protects your data if the source folder is empty by mistake, for example when a disk is not mounted. Adjust it to your volume.

  2. Create the service:

    Terminal
    sudo chmod 700 /usr/local/sbin/rclone-sync.sh
    sudo nano /etc/systemd/system/rclone-sync.service
    Configuration
    [Unit]
    Description=rclone sync
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    Type=oneshot
    Environment=HOME=/root
    Nice=10
    IOSchedulingClass=idle
    ExecStart=/usr/local/sbin/rclone-sync.sh
  3. Create the timer:

    Terminal
    sudo nano /etc/systemd/system/rclone-sync.timer
    Configuration
    [Unit]
    Description=Daily rclone sync
    
    [Timer]
    OnCalendar=*-*-* 04:15:00
    RandomizedDelaySec=20min
    Persistent=true
    
    [Install]
    WantedBy=timers.target
  4. Enable it and run a first pass:

    Terminal
    sudo systemctl daemon-reload
    sudo systemctl enable --now rclone-sync.timer
    sudo systemctl start rclone-sync.service
    sudo journalctl -u rclone-sync.service -n 30 --no-pager

To recover an older version, list the archives then copy the file you want:

Terminal
sudo rclone lsf hms-crypt:archive
sudo rclone copyto hms-crypt:archive/2026-11-18_041500/dossier/fichier.txt /var/tmp/ancienne-version.txt

The versioning advertised on the HMS offer page can complement this mechanism. The versions kept then count toward the billed volume.

Use another service: SFTP example

rclone supports many services, listed in its documentation. Here is how to target another server over SFTP, in this case backup.your-domain.com.

  1. Create a dedicated key, install it on the remote server and record its fingerprint:

    Terminal
    sudo install -d -m 700 /root/.ssh
    sudo ssh-keygen -t ed25519 -N '' -C 'rclone' -f /root/.ssh/rclone_sftp
    sudo ssh-copy-id -i /root/.ssh/rclone_sftp.pub YOUR_USER@backup.your-domain.com
    sudo ssh -i /root/.ssh/rclone_sftp YOUR_USER@backup.your-domain.com true

    On the first connection, compare the displayed fingerprint with the remote server's before accepting.

  2. Add this block to /root/.config/rclone/rclone.conf:

    Configuration
    [backup-sftp]
    type = sftp
    host = backup.your-domain.com
    user = YOUR_USER
    port = 22
    key_file = /root/.ssh/rclone_sftp
    known_hosts_file = /root/.ssh/known_hosts
  3. Test access:

    Terminal
    sudo rclone mkdir backup-sftp:rclone
    sudo rclone lsd backup-sftp:
  4. To encrypt this data too, create a second crypt storage:

    Terminal
    CRYPT_PASS="$(openssl rand -hex 32)"
    CRYPT_SALT="$(openssl rand -hex 32)"
    sudo rclone config create sftp-crypt crypt remote=backup-sftp:rclone/crypt password="$CRYPT_PASS" password2="$CRYPT_SALT" --obscure
    printf 'password: %s\npassword2: %s\n' "$CRYPT_PASS" "$CRYPT_SALT"
    unset CRYPT_PASS CRYPT_SALT

    Keep these values off the server, then set REMOTE="sftp-crypt:" in the script to use this destination.

Update rclone

Terminal
rclone selfupdate --check
sudo rclone selfupdate --package deb
rclone version

After an update, run the sync by hand and check its log.

Troubleshooting

didn't find section in config file

The name before the colon does not match any block in the configuration, or rclone is reading another file. With sudo, check:

Terminal
sudo rclone config file
sudo rclone listremotes

SignatureDoesNotMatch, InvalidAccessKeyId or AccessDenied

Check both keys and the endpoint shown for your service. If the error mentions a region, add region with the value provided by your storage provider, or contact support from your customer area.

RequestTimeTooSkewed

The server clock is off. Check it with timedatectl, then follow our guide Configure NTP.

NoSuchBucket or directory not found

The bucket or the path does not exist. Check its name with sudo rclone lsd hms-s3:. For a source folder, check that it really exists on the server.

failed to authenticate decrypted block - bad password?

The crypt password does not match the data, or the remote file is damaged. Restore rclone.conf from your external copy, without recreating the encrypted storage with new secrets.

--max-delete threshold reached

The number of deletions exceeds your limit, and the operation stops. First check that the source is complete, then verify with --dry-run. Only raise the limit if these deletions are really intended.

file name too long

The encrypted name exceeds the storage limit. Shorten the file names concerned, aiming for 143 characters at most.

The service fails without a clear message

Increase the level of detail by running the script by hand with --log-level DEBUG added to the rclone sync command, then check:

Terminal
sudo systemctl status rclone-sync.service --no-pager
sudo journalctl -u rclone-sync.service -n 100 --no-pager

References