I want to be able to unlock screen, or login to physical user while I'm connected with ssh connection. I know this might be unsafe etc. However that's ok for me at the moment. What options do I have to do this?
2 Answers
The duplicate link I added has some really good Apple Script options.
$ osascript -e 'tell application "System Events"
> keystroke "verysecurepassword"
> key code 36
> end tell'
I might also suggest using LockScreen
. It's a hidden application that comes preinstalled and is protected by System Integrity protection. It will put a lock icon on the screen, lock the keyboard and mouse, and freeze the Touch Bar (Sounds malicious, right?).
System Preferences > Security & Privacy > Uncheck "Require Password...."
To lock the Mac use
$ /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/Support/LockScreen.app/Contents/MacOS/LockScreen
- To unlock the Mac use (non tested but should work)
$ killall LockScreen

- 10,009
Apple distinguishes an ssh session from an actual graphical log in and even restricts some things like MDM enrollment to prevent any remote session from doing an action that is designed for a person in front of the machine to approve.
It depends on your macOS version and your settings if this is trivial or blocked.
Locking is easy, unlocking depends on the security choices and T2 chip presence in the hardware.
For code and API - check out our partner site Stack Overflow - the API to lock a screen is documented there and you might find official Apple developer API and SDK at https://developer.apple.com

- 235,889
-
This actually should be quite secure. On Linux systems with Systemd, you can say:
loginctl unlock-session
, which will unlock for the current user. So you need a way to authenticate as the user anyway. I'm missing this on my Mac. – Tamás Barta Sep 29 '20 at 13:24 -
Apple is placing the decryption keys in a Secure Enclave @TamásBarta so as long as whatever script or framework calls the unlock asks the T2 chip to unlock in an approved way, you’re correct. Apple stores one time keys to NVRAM as part of
fdesetup authrestart
which automates not only unlock, but unlock over a power cycle event. – bmike Sep 29 '20 at 14:50 -
1Wow, thanks for the additional info @bmike, I'm not familiar with the Apple stuff, so I appreciate these details. – Tamás Barta Sep 30 '20 at 22:38
SecurityAgentPlugin
from: https://developer.apple.com/library/content/technotes/tn2228/_index.html#//apple_ref/doc/uid/DTS40007991 The info is rather old, becauseetc/authorization
is moved to thesecurity authorizationdb
-> https://derflounder.wordpress.com/2014/02/16/managing-the-authorization-database-in-os-x-mavericks/ – Mateusz Szlosek Mar 07 '18 at 09:21