Programatically enable Screen Sharing and Remote Login on macOS Big Sur?

Viewed 1046

I'm looking for a way to programatically enable Screen Sharing and Remote Login on macOS to help with automated provisioning of new machines.

I'm running the following code in a .sh script on the new machine:

    # Enable screensharing for remote management
    sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
    sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
    # Enable remote login for remote management
    sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Once run, the Screen Sharing and Remote Login Services are checked as On in the System Preferences > Sharing menu

However when I initiate a screen sharing session using Connect to Server (Cmd + K in Finder) and enter an administrator password, the screen sharing connects but the remote session only sees a black screen.

The screen is displayed through the Connect to Server screen sharing session when I go to the physical machine and uncheck/check "Screen Sharing". However I would like to avoid any manual set up steps if possible.

Has anyone had luck setting up Screen Sharing and Remote Login programatically using a different command/method?

1 Answers

Once I can ssh, I use this snippet:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -users localadmin -access -on -privs -all

I can't recall where I learned it.

Related