Re: LaunchDaemon to run as a particular user

Nathan Sims <[email protected]> Tue, 22 Nov 2011 17:56:08 -0800
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Nov 22, 2011, at 5:31 AM, Michael Babin wrote:

> On Nov 21, 2011, at 11:15 PM, Nathan Sims wrote:
>=20
>> 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.=20
>>=20
>> 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.)=20
>>=20
>> Does anyone know of the tag, or is there another way to do this?
>=20
> I think the one you are looking for is:
>=20
> UserName <string>
>     This optional key specifies the user to run the job as. This key =
is only
>     applicable when launchd is running as root.
>=20
> See the man page for launchd.plist(5), particularly the section "XML =
PROPERTY LIST KEYS".
>=20
Thanks, <key>UserName</key> was exactly what I was looking for. Works =
perfectly!