How to Sync all home dirs as root without changing ownership?

I’ve just set up synchronisation of /home on Kubuntu 20.04 using v1.16.1 and I notice that any newly created files are created as root!

How can I overcome this without having to teach every user how to use Syncthing and then support them when they mess it up? I just want to be the one to set this up for them without having to log in as them.

Thanks in advance!

I strongly encourage you to setup a systemd user service for each user. While this is more work initially, you won’t suffer from permission issues :wink:

Okay, but how will I configure it for each user?

Actually the bit about you being in control, not users, means systemd system services sound like the right tool. Info about that part can be found here: Starting Syncthing Automatically — Syncthing v1 documentation

Anyway the more involved bit will be managing the various configurations. Depending on what your actual setup/use-case is, using some config management solution might be a good idea (e.g. ansible). Can’t comment further without knowing more about that.

Actually I already read that information before choosing to it use system.d as root because if run as a user there are two major issues:

  1. If the user doesn’t log in on PC1 for 2 weeks but uses PC2 instead, his home directory will not be updated on PC1, which is the master copy which is backed up to a NAS every hour.

  2. As you mentioned trying to configure the syncronising for each user becomes significantly harder and monitoring the result for each user simply won’t even happen!

In the absence of a reasonable solution I propose to just add a cron script to run every 5 minutes, which will change the ownership of all files in each users home directory, back to the ownership of that user. My understanding is that only newly added files will be affected and I can’t think of any downsides.

Thanks for your inputs by the way and your fast responses. What do you think of my workaround? Any major issues?

Issue 1 is only relevant for user services, system services always run for every user even without login, not only if it is running as root. Just do the steps in the documentation under “How to set up a system service” for every user.

Issue 2 still remains with this solution since one instance is running for every user.

Thanks Alex. It turns out that a system service is what I’m currently using.

I specified root as the user and this is resulting in all newly transferred files being owned by root.

All other issues are no issue though since all home directories are syncronised regardless of who is logged on and I can also monitor all directories in one screen using the web GUI.

So it’s just ownership which is the issue. It would be a nice touch if as well as the “ignore permissions” option (which I’m not using), there was another box for “maintain ownership”. That would be fantastic.

The user ID’s match on all machines, so translation would not be necessary (but would be a nice touch probably for some people if it could do that too).

It’s looking like I’m going to be needing a chown -R script I think?

There is such an option. Just to reiterate: It is not recommended to run Syncthing as root, and this functionality is “advanced”, as in you need to understand what it does and you get to keep the pieces if things fall apart :wink: all: Copy owner/group from parent (fixes #5445) by calmh · Pull Request #5479 · syncthing/syncthing · GitHub

Well you could also configure asystem service for each user if you avoid port clashes.

Now that’s exactly what I’m looking for. I’ll study it and see if I can get it working on one folder first (of a lesser user).

I will likely migrate from running as root, to a new dedicated user too, once the dust has settled.

Many thanks everyone for all of your inputs (and for contributing to such a worthwhile community project).


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.