0

I created a user called dummy.

I login using Terminal into dummy and try to put Mac to sleep using pmset sleepnow. It does NOT work: Sleep error 0xe00002c1; You must run this as root..

I log into dummy using Fast User Switching in MacOS GUI. I switch back to my main user [keeping dummy logged in thanks to the Fast User Switching GUI]. I login again to dummy using Terminal and try pmset sleepnow. It's working now!

  1. Why is that?
  2. How does it work that the command requires sudo, unless I'm logged in the GUI [then it doesn't]?
  3. What are other commands that magically start working if logged in using the MacOS GUI?

EDIT: Previously I have thought it was like that because of the dummy being a "standard" account – I've just tested that it is the same issue for "administrator" accounts as well. Still, the questions remain: why/how does it matter, being logged in the GUI, for some commands to work.

1 Answer 1

1

It's apparently implementing the same check that would allows dummy to use the Sleep command in the Apple menu -- anyone who is logged into the GUI is allowed to perform certain actions.

Rather than check whether the command is coming from the GUI itself, it just checks whether the user who runs the command is also logged into the GUI. Even if their GUI is suspended due to fast user switching, it still allows the dummy user to execute the command.

Even if pmset didn't allow this, you could achieve the same thing with an AppleScript that clicks on the Sleep menu item.

The general idea is that someone who has physical access to the machine is allowed some additional privileges without having to re-authenticate or use sudo. Logging into the GUI indicates that you have physical access.

Other things you can do without having to re-authenticate are the Restart and Shutdown commands in the Apple menu (unless there are other users logged in, then it asks for the admin password). I don't know what the CLI equivalents are (other than the traditional Unix shutdown command), so I don't know if they also implement similar bypass of sudo.

2
  • i see. anyway, still not an answer to my questions: why [make case for just gui], how [what are the changes that allow it], what other apps [besides pmset]?
    – MacDada
    Commented Oct 30, 2022 at 12:53
  • I've added to my answer.
    – Barmar
    Commented Oct 30, 2022 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .