How can I have a non-elevated script execute another specific script as root without requiring a password from the user?
5
votes
3
answers
1359
views
I have a script, let's call it
on-event.sh
, that's going to be run at specific times, such as when a particular application launches or quits. The script itself will run as the current user (not root) since I'll be using BetterTouchTool to execute it.
However, on-event.sh
needs to somehow trigger the execution of another script that must run as root, which I'll call run-as-root.sh
. run-as-root.sh
will execute some commands to load or unload specific third party launch daemons (not my own), hence the need to run as root. Since it'll all be happening in the background, it needs to happen without requiring user intervention, so it can't use sudo
or AppleScript's with administrator privileges
. Because of the obvious security implications, I only want it to be possible to execute run-as-root.sh
as root and not any arbitrary script or terminal command.
One option I'm already aware of is I could create a launch daemon that opens a socket, waits for a connection, and then executes run-as-root.sh
, and have on-event.sh
connect to that socket. But that's a more heavy weight solution and I'm hoping for an easier way to do this.
How can I set it up so this is possible?
Asked by Bri Bri
(2930 rep)
Apr 30, 2024, 02:37 PM
Last activity: May 2, 2024, 05:24 PM
Last activity: May 2, 2024, 05:24 PM