3/11 I need to start a daemon as a specified user at startup time, or
soon after, on FreeBSD. How can I do this?
\- you might be able to do it with su, but if it needs to bind to a
privilaged port and then relinquish priv, then it is more
involved, say if you want to run named as an unpriv user,
as we do. so the daemon is in fact in the details, e.g. if
you are also chrooting etc. --psb
\_ Actually, it's not so complicated-- ideally, it would simple
enough to do with a nologin/nopass user and an rc.d script. It
doesn't need any special privileges. su wouldn't really
work, because it requires a shell. If I try
sudo -u user daemon
then sudo complains that I'm already root and don't need to
sudo.
\_ Are you insistent on not having a shell for "user." I
don't see why su -u user -c "daemon" wouldn't work for
you (assuming you allow user a shell). Or try:
chsh -s "/bin/bash" user; su -u user -c "daemon";
chsh -s "/bin/false" user. And let me know if that works.
\_ Do you have the source for the daemon? If so, just patch main
so that it takes two additional args one for the uid/user and
the other for the gid/group to switch to after starting up.
If the daemon needs to bind to a port, it might be more complex, |