2

It’s possible to restart a Mac from the command line (sudo shutdown -r now). It’s possible to log out from a Mac from the command line (sudo pkill loginwindow). But is it possible to force a Mac to log in from the command line? As in a full log in of an account, GUI-wise, not just logging in via SSH to the Mac via the Terminal.

8
  • 1
    What about connecting over screen sharing (the VNC protocol)? – Gordon Davisson Dec 20 '20 at 19:28
  • I've not tested this with newer macOS versions. Apple may have locked this down requiring you to set it up in the GUI. So changing the user that is automatic logging on may not be feasible. This older article covers what's required to turn on the Automatic login setting from System Preferences -> Users & Groups -> Login Options. apple.stackexchange.com/questions/264068/… – James Brickley Dec 20 '20 at 19:52
  • Hopefully this isn’t an XY question and you need to do something else and this seems the first step to the final goal... – bmike Dec 21 '20 at 3:14
  • @bmike I don't know what an XY question is, but I want to be able to start Mail remotely after a restart, which requires logging in. – Calion Dec 21 '20 at 18:33
  • 1
    Sorry. It’s shorthand for a question about a solution. An intermediate step meta.stackexchange.com/search?q=XY+ – bmike Dec 21 '20 at 20:52
0

I created something like this for Remote Desktop to signing a xServe. We had more than 1 account, and we had to sign un with both username and password. I ran this remotely through the terminal to prior to pulling up the screen.

`osascript -e 'tell application "System Events"' -e 'keystroke "USERNAME"' -e 'keystroke tab' -e 'delay 0.5' -e 'keystroke "PASSWORD"' -e 'delay 3.5' -e 'keystroke return' -e 'keystroke return' -e 'end tell'`

Just replace the USERNAME and PASSWORD and that should work. I have not tested this on a more recent OS, but I hope this helps.

0

Yes.

  1. Enable FileVault so you can escrow user and password securely
  2. sudo fdesetup authrestart sets the machine to restart and log in as the specified user after the restart.

This works for me remotely on new Macs with Big Sur. You may need ssh Or Apple Remote Desktop to log in remotely, but the above command works when I can’t be there to get past the FileVault log in screen and I’m remote and it generates a graphical log in from a remote ssh session.

Once the restart completes, Mail can start. Set it to launch at log in if you wish and you’re set. You don’t need auto log in since this works to make auto log in one time only.

You must log in to answer this question.

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