Run Script as Root

Hey guys, I need to run a script as the root user, but I cannot give out the login information and password to the person running the script. The shell script needs to be run as root.

Is there a way to include the root username and password in the script so that it can be ran from any admin account but make the script run only? Is this a secure way to do that?

I am trying to make it a fast process where they simple double click the Automator application I created and the script executes without any further user interaction. (ex: no need to enter any passwords)

Referring to 10.8-10.11 Machines. I have about 7k of them.

Thanks in advance!

I’d look into creating an installer, that runs this as a launch daemon

This would allow you to install the relevant components, and get the script to run, as you wish, as root.

This would mean that it would continue to run as root, should you need to repeat the task, without user input or credentials

Strings are readable in read only scripts so using this format is far from safe.

Of course you may build the password - here the variable mp - by successive concatenations like the code below.

set a to "a"
copy a to m
set a to "b"
set m to "@" & m & a
set a to (125 * 3)
set a to a div 5 as text
set mP to m & a
set a to "Ù"
set mP to mP & a

Here it builds the string “@ab75Ù”
It seems that deciphering the read only code would not be easy.

Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) lundi 6 juin 2016 20:49:04

This is really something that the keychain is designed for, but unfortunately Keychain Scripting has been discontinued. You can use the keychain access in my BridgePlus library, but that won’t work before OS X 10.9.