How to enable OS X screen sharing from the command line

After a recent OS X update mangled my Mac Mini’s sharing setting I had to learn how to enable OS X screen sharing from the command line. Here’s how.

One of the first articles my favorite search engine turned up was blog post on pivotal.io. It’s really helpful and attracted a few comments which give further insights into how to enable OS X screen sharing from the command line. The only downside? It was written nearly three years ago and I have reason to believe that OS X El Capitan (10.11.2) behaves slightly differently now than explained in that article.

In El Capitan if you enable Remote Management, which includes screen sharing, you won’t be able to control screen sharing individually. So, if you enable Remote Manager on the command line you will be able to connect to the other Mac (the one without a screen) but you cannot turn on screen sharing and turn off Remote Management. And of course, the moment you turn off Remote Management in the sharing system preferences you loose your screen sharing session :-/.

If you try to enable only screen sharing on the command line OS X reveals that that service has actually been disabled. This means you need to “force load” the respective launch deamon.


$ ssh <user>@<mac-without-screen>
$ sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist
/System/Library/LaunchDaemons/com.apple.screensharing.plist: Service is disabled
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

The -w switch on the last line behaves as follows (launchctl man page):

Overrides the Disabled key and sets it to false or true for the load and unload subcommands respectively. In previous versions, this option would modify the configuration file. Now the state of the Disabled key is stored elsewhere on disk in a location that may not be directly manipulated by any process other than launchd.

One thought on “How to enable OS X screen sharing from the command line

Leave a Reply