Running Syncthing in an unprivileged LXC on Proxmox

AI Disclosure:
Google is terrible, so I stuck to official docs when I could and peppered Claude with questions when I couldn’t. Any flashes of brilliance or boneheaded mistakes beyond that are mine alone.


Overview

I have multiple machines which I use frequently, and sometimes it’s a challenge to keep my documents and project files in sync across systems. I could just create a network share on the NAS and set up tailscale or netbird for remote access, but in general if you can avoid exposing something to the Internet even through a VPN, then you probably should avoid it. I’m looking at syncthing to help me solve this problem.

I wrote this guide to fit my network which has storage managed by a NAS running TrueNAS with compute done by a separate machine running Proxmox, but many of the principles will apply to other systems as well. I’ll be assuming you have some familiarity with Linux and Proxmox, and I won’t be going in depth into the specifics of managing TrueNAS or the network side of things on topics such as VLANs, or DHCP reservations. Comparisons of LXC with docker and other features of LXC such as chroots or cgroups are also outside of the scope of this guide.

Initial setup

To create an LXC in Proxmox you need to start with a pre-packaged tarball used to initialize the containers root filesystem. Proxmox calls these templates. Templates can be downloaded from a repository, or converted from an existing LXC. This can be done through the admin UI, or open a shell and do it from the command line. My distro preference has always been Debian, so I used the standard Debian 13 image as my template for the syncthing LXC. The choice of distro isn’t particularly important here though so use whatever you’d like. Something with syncthing v2 in its package repo would allow you to skip a step later on if you choose to use something else. I took the extra step because I can’t waste skull sweat these days keeping track of variations between distributions.

root@proxmox:\~# pveam update
root@proxmox:\~# pveam available --section system | grep debian-13
system debian-13-standard_13.6-1_amd64.tar.zst amd64
system debian-13-standard_13.6-1_arm64.tar.zst arm64
root@proxmox:\~# pveam download local debian-13-standard_13.6-1_amd64.tar.zst

At the time I’m writing this 13.6-1 is the latest version.

Next, create the container using this template.

root@proxmox:~# pct create 106 local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst \
  --hostname syncthing \
  --unprivileged 1 --features nesting=1 \
  --cores 2 --memory 2048 --swap 512 \
  --rootfs local:8 \
  --net0 name=eth0,bridge=vmbr1,ip=dhcp,type=veth \
  --ostype debian --timezone host \
  --onboot 1 \
  --description "Syncthing v2"

Adapt the command to fit your network. I have containers and VMs on a separate VLAN, so a new install probably won’t have the vmbr1 device created that I’m using here. In addition, replace 106 with whatever works in your system as a container ID. They need not be sequential, but they do need to be unique across both containers and VMs. Keep in mind Proxmox embeds these IDs in filenames for your disk images and backup archives, so don’t plan on changing them later without some hassle. Multiple users would increase the resources required for the Syncthing container its self, but for just me the requirements are modest. Nesting permits nested namespaces in the guest container exposing /proc and /sys of the host to the guest and is on by default in the GUI. Unprivileged containers are what this guide is all about and are also enabled by default.

After creating the container, pct config 106 | grep eth0 will get you its mac address which can be useful for creating a static reservation.

Creating an NFS user and dataset for syncing

On TrueNAS 26 user management is under Credentials → Users. Create a user named sycthing, then create a dataset that will be mounted from the syncthing LXC. I called it tank/sync with owner syncthing:syncthing and permissions of 750. For some additional redundancy it’s a good idea to set up a periodic snapshot task for this dataset as well. If you’re using something other than TrueNAS you’ll probably be fine so long as you’ve got an NFS server to work with that offers the same features.

Next, you’ll need a network share so Proxmox can access the synced data on the NAS. TrueNAS doesn’t have an ACL preset for NFS shares, so the generic option is fine here. I created a share of /mnt/tank/sync with hosts restricted to only the Proxmox machine and mapall user and group to the syncthing user created earlier.

Once the share is created the mount point for it needs to be configured on the Proxmox host. An unprivileged container can’t manage its own NFS shares, so it has to exist on the host and then be mounted in the container. Create the mount point and add it to /etc/fstab.

root@proxmox:~# mkdir -p /mnt/nfs/sync
root@proxmox:~# cp /etc/fstab /etc/fstab.bak-$(date +%F) # yolo-ing fstab makes me nervous  :)
root@proxmox:~# echo x.x.x.x:/mnt/tank/sync /mnt/nfs/sync nfs vers=4,rw,noatime,_netdev,nofail,x-systemd.automount,x-systemd.mount-timeout=30 0 0' >> /etc/fstab

The options used here are a reasonable default with some hedges that should lessen the impact on Proxmox should the NAS be offline or for some reason unavailable. If you’re building out a homelab as training for building out a “real” production system, then remember that relying on systems to always be online is a strategy that will eventually fail. However, placing more guardrails tends to make the system more opinionated in how work gets done using it, so there’s a balance to be found there. Where that balance is depends on the system you’re building and the requirements of its users. Reload services for the changes to take effect.

root@proxmox:~# systemctl daemon-reload
root@proxmox:~# systemctl start mnt-nfs-sync.automount

Once that’s done you can configure the LXC with the mount point you just created and start it up.

root@proxmox:~# pct set 106 -mp0 /mnt/nfs/sync,mp=/srv/sync
root@proxmox:~# pct start 106

Installing Syncthing

A new install will likely need some package updates, and as I mentioned earlier Debian 13 has an old version of Syncthing in its repo. You’ll need to add GPG keys for the syncthing repo and pull v2 from there if you want to use it. For editing sources, I’d normally just open the file up in a text editor and edit from there. I’m just formatting it this way for the sake of display in the guide.

root@proxmox:~# apt update && apt full-upgrade -y
root@proxmox:~# apt install -y curl ca-certificates
root@proxmox:~# mkdir -p /etc/apt/keyrings
root@proxmox:~# curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
root@proxmox:~# echo "deb \[signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg\] https://apt.syncthing.net/ syncthing stable-v2" > /etc/apt/sources.list.d/syncthing.list
root@proxmox:~# printf "Package: \*\\nPin: origin apt.syncthing.net\\nPin-Priority: 990\\n" > /etc/apt/preferences.d/syncthing.pref
root@proxmox:~# apt update && apt install -y syncthing

There are some things which will stay on the root filesystem. Configuration files and the local SQLite database syncthing uses are best left there. It’s generally asking for trouble to host databases directly on NFS fileshares, so create a local user and don’t do that.

root@proxmox:~# useradd --system --create-home --home-dir /var/lib/syncthing --shell /usr/sbin/nologin syncthing
root@proxmox:~# read -rs -p 'GUI password: ' P; echo
root@proxmox:~# printf '%s\n' "$P" | runuser -u syncthing -- syncthing generate --gui-user=admin --gui-password=-
root@proxmox:~# unset P

The read command is a nifty trick for local user creation. It allows you to enter the password from stdin without recording it in the process list or shell history.

Next, you’ll probably want the GUI for syncthing remotely accessible. Open /var/lib/syncthing/.local/state/syncthing/config.xml in your favorite text editor and replace the address element referencing 127.0.0.1:8384 with the address you’d like it to listen on. Start the systemd service once that’s done.

root@proxmox:~# systemctl enable --now [email protected]

You should now be able to hit port 8384 of the host you configured in a browser to bring up the GUI and complete the setup from there. One of the first things you’ll want to do is go to Settings → General → Edit Folder Defaults and set the default path to /srv/sync/ to match the mount point created earlier so that data lands on the NAS not local container storage.

For installing syncthing on your other devices there’s an official docker container, or just install it using your package manager. You’ll get the same GUI there to help you finish the installation. If you’ve got a setup like mine where the syncthing LXC is in a different vlan from your other devices, then you may need to manually add remote devices since broadcast messages from the LXC may not reach your devices.

That wraps up the step-by-step portion of this guide. From this point the setup varies depending on how exactly you want the data syncing to function. This is where you get to define what devices will participate in sharing and what folders will be shared across those devices as well as your preferred balance of local and remote functionality.

If you’re curious what “unprivileged” really means…

An unprivileged container takes advantage of kernel namespacing to remap the user and group IDs across the container and host. The default uid map below shows that for the syncthing LXC process guest uid’s are mapped to host uid’s starting at 100000 with 65536 possible entries. Any security issues happening within the container should affect a high-numbered unprivileged user on the host rather than host root at uid 0.

root@proxmox:\~# lxc-info -n 106 -p | awk '{print $2}'
2104774
root@proxmox:\~# cat /proc/2104774/uid_map
0 100000 65536

The gid_map would show the same thing, but remember there’s an NFS share in the mix as well. Configuring the NFS user with mapall user and group means the files on the tank/sync dataset will be created with the uid/gid of the NFS user and not the guest container user under which syncthing is running.

root@proxmox:~# cd /mnt/nfs/sync/
root@proxmox:/mnt/nfs/sync# ls -l
total 1
drwxr-x--- 3 3001 3000 5 Nov 28 20:28 documents

By default TrueNAS starts creating uid’s at 3000, so that’s what you’re seeing here. If you look in the LXC at the same files you’ll see nobody and nogroup probably with a uid of 65534. uid 3001 does not exist in the LXC, so this is what the kernel does with uid’s that don’t map to a known user. It doesn’t change the ownership of the files or permissions enforced by the NFS server. If you had a need for multiple distinct NFS users each with their own permissions, then you’d need to turn off mapall, and do custom remapping for the uid’s in Proxmox. At that point though you’re probably better off using Nextcloud or some other tool with better multi-user support.

1 Like

I’d have migrated to Syncthing from Resilio Sync long ago is Syncthing supported microSD cards on Android. Sadly, it doesn’t.