How to run Syncthing as MY user on FreeBSD?

Hello,

The Syncthing package on FreeBSD creates a user and group called “syncthing” and the daemon is run by said user/group. This is causing me file permission issues and not allowing me to sync my files between my other systems. I tried many things to try and solve this issue, such as changing directory/ownership permissions, adding my user to the “syncthing” group, etc, but no luck at all. On Linux, I can set up Syncthing for my user simply by using systemctl --user, but on FreeBSD, there is no such thing.

I went into rc.conf and added the lines syncthing_user="lv426" and syncthing_group="lv426" but that makes no difference. Restarting the service, the process dies after a few seconds. As an experiment I modified some of the variables in /usr/local/etc/rc.d/syncthing and was able to get my files synced, but now the service was running as root and files owned by root too, which is not what I want.

Simply, how can I get my user, “lv426” to run the daemon and own the files?

You’d have to check the FreeBSD package documentation for how they did the specifics, but in principle you can just run it as your user however you prefer. I’m not sure of the preferred way to do that automatically for a given user on FreeBSD.

Hey there,

I’m not sure how you have designed/idea of file permissions. But as I understand correctly you want to use your “human user” account to have syncthing running as instead of the package default syncthing:syncthing. This is a common UNIX/Linux “problem”. You can solve this with filesystem ACL (but takes some effort to setup correctly), then you have extended permissions on top of user,group,others. Probably you don’t want to go down that ACL rabbit hole.

So indeed under FreeBSD there is a simple init/process management system with rc. Under the hood it uses the daemon program to put applications in the background and is able to change the running user and group.

I have tested it on my FreeBSD development machine and it works without problems. Keep in mind the default home directory points not in the user $HOME folder but to /usr/local/etc/syncthing Which is a weird place in my opinion. It is highly likely user lv426 has no permissions to it. Maybe the fix for now is to also set the syncthing_home variable in rc.conf so it points where $HOME is. But as you mentioned you changed the system /usr/local/etc/rc.d/syncthing need to revert to the supplied version by removing the package and reinstalling.

The process/init manager of FreeBSD is very simple compared to systemd but I miss some features like running the service multiple times as user like systemctl enable syncthing@jerry.

Hope this helps.

Sorry for the late reply guys, I just got back to troubleshooting this tonight.

I got it working, but it is still not the ideal setup, as it is running as the syncthing user.

@xor-gate I am familiar with Unix/Linux permissions, but I don’t use ACLs and I think that is overly complex for what I want to do here.

I set the variable as you suggested, but that line, /usr/local/etc/rc.d/syncthing is actually for setting the config directory. I did it anyway as a test, but it just polluted my ~/Sync directory with cert.perm, config.xml, key.pem, etc. After doing that, I still couldn’t start the service.

Next, I reinstalled the package and went over everything again; Still couldn’t get the service running. I tried editing the file /usr/local/etc/syncthing/config.xml, but gave up after nothing changed.

The solution to get the service running was to chown the Sync directory as syncthing:syncthing. After that, I had to chmod -R 770 the directory, just so my user could access files in there. I don’t like this solution, because I have to chmod every time something new is added, plus it pollutes the "Recent Changes’ in the Web UI.

If anyone has a better solution allowing me to use my user that would be great. Not sure why this is so difficult compared to Linux.

Alright, I think I solved the issue. I hunted down every file owned by the syncthing user/group and then changed the permissions to my user/group. Below are the files you need to change…

  • Everything in /usr/local/etc/syncthing
  • The log file in /var/log/syncthing.log
  • The process file in /var/run/syncthing.pid
  • In /etc/rc.conf change the variable syncthing_user and syncthing_group to your user and group. Then reboot.

Hope this helps someone.

1 Like

Glad you worked it out. :slightly_smiling_face:

Assuming that the end goal is to autostart Syncthing whenever FreeBSD is rebooted and not just during login time, another option would be to use cron. Add a crontab entry for your user lv426 like so:

@reboot /usr/bin/syncthing serve --no-browser --no-restart --logflags=0

If there are multiple users, just make sure that each one uses different port numbers for at least the web UI.

1 Like

That’s a good suggestion. Thanks!