Applescript/Bash: Check if root is enabled

Hi Community,

Is there a function in applescript or if not, an xml file that could be read with bash that will let me check if the root account has been enabled? Thank you.

Posted on Sep 26, 2011 2:24 PM

Reply
9 replies

Sep 26, 2011 2:59 PM in response to chumponimys

"Don't you need to run that as sudo to access Authentication Authority? "

Well, from an admin account I don't have to preface the command with sudo.


"... how would you test?"

Enable the root user account and check if the AuthenticationAuthority key is set in Directory Service with the command I provided.


If you are an admin user you could produce a root shell and check /var/db/shadow/ for root's shadow password file. If the file exist then the root account is enabled.

Sep 26, 2011 3:24 PM in response to Mark Jalbert

twtwtw:

thank you so much, this is just the kind of creative solution I was looking for. The only problem here is that i'm not sure how to use last. I tested it out on my different accounts doing "last -1 the_user" and for some accounts it will give me something like:

the_user ttys001 Mon Sep 26 15:00 - 15:01 (00:00)

which I assume to be the right thing, but other accounts will give me this:

wtmp begins Wed Sep 21 16:39

What would it look like if the account had never been logged into?


Mark:

Firstly, /var/db/shadow/hash only exists in the operating systems before lion, and i am going to be using this in Lion, so that is not going to work for me. Also, this script is meant to be run from any account, not just admin or root, so i'm not sure about reading root. Lastly, wouldn't it be:

dscl . read /var/root AuthenticationAuthority

Sep 26, 2011 3:30 PM in response to chumponimys

I don't have root enabled, so I can't be sure what it looks like under those conditions, but I'm thinking that if you just toss it through grep you should get what you want:


last | grep -c root


if that returns 0 then root has never logged in. however, the command takes a ridiculously long time to run (almost 4 seconds on my machine) so I'd see this as a last resort. There must be a better way.

Sep 26, 2011 4:41 PM in response to twtwtw

Thank you so much all. I ended up using twtwtw's method with last (it turns out the computer I was testing it on before had a corrupt library file and when I tried it on another computer it started working perfectly). For other users, here's the final snippet:


set rootTest to (do shell script "last root")

set rootTest to paragraphs of rootTest

set rootTest to item 1 of rootTest

if rootTest is not equal to "" then

display dialog "Root is Enabled!"

end if

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript/Bash: Check if root is enabled

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.