Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Tools
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Enabling OS X Screen Sharing from the Command Line

Brian Cunnie
Tuesday, January 8, 2013

There are several ways to enable screen sharing on OS X Mountain Lion from the command line.  The first method is an old standby:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -off -restart -agent -privs -all -allowAccessFor -allUsers

This will work in 99% of the cases, but there may be some situations when it’s not quite enough.  The above command enables Screen Sharing by enabling Remote Management; however, we lose the ability to add fine-grained control to who can connect & those who can’t.

Here’s another way to enable screen sharing from the command line:

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

In the second example, we enable only Screen Sharing, not Remote Management. This allows us to use System Preferences to restrict who can screen share to our machine (e.g. local administrators, network administrators). We use the second example when configuring our authentication servers remotely.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

3 Comments

  1. Marco Carvalho says:

    Trying to remotely connect to a Mac OS X 10.7.4 from another mac (10.8)

    So, the target machine had screenshare already set from a previous user. I only had ssh and sudo access to it. Here’s the command I ran to reset the password to 123pass (last param) for the VNC:

    sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -off -restart -agent -privs -all -allowAccessFor -allUsers -clientopts -setvncpw -vncpw 123pass

    And then I’m using the chicken (AKA Chicken of the VNC) as my vnc client.

    Thank you so much for posting this.

    January 10, 2013 at 7:52 pm

  2. Alessandro Volz says:

    I think you’re supposed to load the agent, too.

    Here’s a script I’m using:

    #!/bin/bash
    /usr/libexec/PlistBuddy -c ‘Set :com.apple.screensharing:Disabled NO’ /private/var/db/launchd.db/com.apple.launchd/overrides.plist
    launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist
    for userid in $(ps -Ajc | grep loginwindow | grep -v grep | awk ‘{print $1}’); do
    if [ "$userid" = "root" ] ; then
    launchctl load /System/Library/LaunchAgents/com.apple.screensharing.agent.plist
    else
    su “$userid” -c ‘launchctl load /System/Library/LaunchAgents/com.apple.screensharing.agent.plist’
    fi
    done

    April 29, 2013 at 3:16 am

    • Brian Cunnie
      Brian Cunnie says:

      Alessandro, nice script. And yes, you’re right: the agent needs to be loaded. Although in my second example I load the agent explicitly using launchctl, in the first example it isn’t necessary—kickstart loads it on my behalf.

      April 29, 2013 at 5:22 pm

Add New Comment Cancel reply

Your email address will not be published.

Brian Cunnie

Brian Cunnie
San Francisco

I'm a systems administrator at Pivotal Labs. I've worked at a slew of startups and with a slew of UNIXes (OS X, Linux, FreeBSD, OpenBSD, HP-UX, AIX, Solaris/SunOS UTS, Xenix, Ultrix, and even the original UNIX). In my spare time I play rugby.

Recent Posts

  • Populating Null Keys using OS X’s PlistBuddy
  • Installing FreeBSD 9.1 on Soekris net6501 via PXE
  • QuickBooks “Error: Connection Has Been Lost”
Subscribe to Brian's Feed

Author Topics

keys (1)
null (1)
PlistBuddy (1)
freebsd (1)
net6501 (1)
netboot (1)
pxe (1)
pxeboot (1)
soekris (1)
ops (5)
vlan (1)
chef (2)
open directory (1)
bonjour (1)
djbdns (1)
dns (1)
dns-sd (1)
tinydns (1)
agile (3)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Tools
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >