I have an executable that needs to run every time a user logs in. It needs to run in the context of that user, but with root permissions, as if the user had run it with
If I create a Launch Agent (in
/Library/LaunchAgents), or a Launch Daemon with the
UserName property set, it runs as the user (as desired), but I cannot do anything that requires elevated privileges.
If I create a Launch Daemon (in
/Library/LaunchDaemons) it runs as root (with the desired privileges), but without any user context. If I use
su <username> -c "<command>" or
sudo -u <username> <command> from the Launch Daemon, I can then run a command as the user, but it runs without sudo privileges.
Is there a way to run a launch agent with sudo permissions?