Discussion:
LaunchDaemon to run as a particular user
Nathan Sims
2011-11-22 05:15:30 UTC
Permalink
I need to have a background daemon process that the system runs under my user automatically, 24/7, even when no one is logged in to the machine.

I created a plist and placed it in /Library/LaunchDaemons, and the system loads it up, but it runs as root, not my user. I've seen this done before by adding a certain tag in the plist file (the name of which I forget), but after googling around for a while I still haven't identified which tag it is. (I know a launch agent runs as the user, but only when the user logs in, which is why I need it to be a daemon.)

Does anyone know of the tag, or is there another way to do this?
Michael Babin
2011-11-22 13:31:55 UTC
Permalink
Post by Nathan Sims
I need to have a background daemon process that the system runs under my user automatically, 24/7, even when no one is logged in to the machine.
I created a plist and placed it in /Library/LaunchDaemons, and the system loads it up, but it runs as root, not my user. I've seen this done before by adding a certain tag in the plist file (the name of which I forget), but after googling around for a while I still haven't identified which tag it is. (I know a launch agent runs as the user, but only when the user logs in, which is why I need it to be a daemon.)
Does anyone know of the tag, or is there another way to do this?
I think the one you are looking for is:

UserName <string>
This optional key specifies the user to run the job as. This key is only
applicable when launchd is running as root.

See the man page for launchd.plist(5), particularly the section "XML PROPERTY LIST KEYS".
Nathan Sims
2011-11-23 01:56:08 UTC
Permalink
Post by Michael Babin
Post by Nathan Sims
I need to have a background daemon process that the system runs under my user automatically, 24/7, even when no one is logged in to the machine.
I created a plist and placed it in /Library/LaunchDaemons, and the system loads it up, but it runs as root, not my user. I've seen this done before by adding a certain tag in the plist file (the name of which I forget), but after googling around for a while I still haven't identified which tag it is. (I know a launch agent runs as the user, but only when the user logs in, which is why I need it to be a daemon.)
Does anyone know of the tag, or is there another way to do this?
UserName <string>
This optional key specifies the user to run the job as. This key is only
applicable when launchd is running as root.
See the man page for launchd.plist(5), particularly the section "XML PROPERTY LIST KEYS".
Thanks, <key>UserName</key> was exactly what I was looking for. Works perfectly!
Loading...