Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Start screen sharing remotely in Terminal Network
Assume you want to do some work on a remote Mac via 10.5's Screen Sharing, but you forgot to enable Screen Sharing before you left the remote Mac. You're now a good distance away, and apparently stuck. Fortunately, because the screen sharing system uses launchd to monitor its state, enabling and disabling is as simple as adding a file in the remote Mac's /Libary/Preferences folder. (Note that you'll need to be able to login to the remote Mac via ssh to run these commands on that Mac.)
$ cd /Library/Preferences
$ echo -n enabled > com.apple.ScreenSharing.launchd
To disable screen sharing:
$ cd /Library/Preferences
$ rm com.apple.ScreenSharing.launchd
If you have a Finder window open with the remote Mac selected in the Shared section, you'll even note the icon for Screen Sharing coming and going as you do this.
    •    
  • Currently 3.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (15 votes cast)
 
[98,132 views]  

10.5: Start screen sharing remotely in Terminal | 21 comments | Create New Account
Click here to return to the '10.5: Start screen sharing remotely in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Start screen sharing remotely in Terminal
Authored by: Pedro Estarque on Mar 25, '08 08:27:11AM

Wouldn't you need do sudo since you are in root /Library ?



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: leamanc on Mar 25, '08 09:17:56AM

Not if you are an admin user. You would need root power to write /System/Library.



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: leamanc on Mar 25, '08 11:46:49AM

Correcting myself somewhat.

As is implied in the hint, you can write to /Library/Preferences as an admin user without using root.

Writing to directly to /Library, however, requires root power, as that folder is read-only for admin users (most of the subfolders are writable by the admin group, though).



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: Pedro Estarque on Mar 25, '08 07:11:01PM

Actually I think this is the correct situation:
If the user has created the launchd file through the System Prefs sharing panel, than you'll need sudo to rm it. But if it's disabled in System Prefs, than yes, you can run the command as admin only, as you have write access to the Preferences folder.

In short, you have write access to the folder as an admin but not to the file created by the System Pref.

Great tip by the way!



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: corienti on Mar 25, '08 01:41:15PM

Not if you're logged in as root :-)



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: luigi193 on Mar 25, '08 10:39:57AM
OMG awesome hint!!!!

[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: shapiro on Mar 26, '08 09:17:00AM

This should always work:
[code]
sudo sh -c "/bin/echo -n enabled > /Library/Preferences/com.apple.ScreenSharing.launchd"
[/code]

all on one line.



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: ccjensen on Mar 27, '08 05:33:11AM

this doesn't seem to work quite right. If I have screen sharing turned on in my servers system preferences, and log in using screen sharing and disable it using the system preferences GUI, I lose the connection.
If I do the same, but instead of using the GUI I delete the file from the terminal, the connection remains and I can disconnect and reconnect. I shouldn't be able to do this if the screen sharing plist file is gone. Any ideas?



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: joelbruner on May 29, '08 09:23:24AM

I recall hearing at WWDC about how the plists are read in by the GUI tools using Cocoa events (or Apple Events called by a Cocoa app) this is the case for many plist controlled items like screensaver password and some others. So when you delete a plist you need a way to fire of the right event to the system so it refreshes. (No I haven't Googled it but there's the hint :)



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: wOOge on Jun 25, '08 06:39:14AM

AWESOME hint... save my arse many times.

---
wOOge
http://www.axonz.com



[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: dmarkow on Sep 11, '09 07:18:54AM
In Snow Leopard (10.6), you need to do this to the file /private/etc/ScreenSharing.launchd instead of /Library/Preferences/com.apple.ScreenSharing.launchd

[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: mael on Jan 03, '10 03:00:58AM
Not for me in 10.6.2. It still is
sudo sh -c "/bin/echo -n enabled > /Library/Preferences/com.apple.ScreenSharing.launchd"
here...

[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: hiawatha on Jul 14, '10 03:49:19PM

I verified on Mac OS X Server version 10.6.3 that dmarkow's comment was accurate. A file named "/private/etc/ScreenSharing.launchd" with text "enabled" as its contents was required to get screen sharing working.



[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: dogfacedboy on Oct 15, '10 07:59:00AM

Thank you! Have used this page for ages to remind myself of how to turn it on under 10.5, then a headless 10.6 server became unresponsive to ScreenSharing a couple of days ago. Would've saved myself a lot of trouble (and probably the reinstall) if I had scrolled through the comments sooner!

Thanks! :-)



[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: zacht on Nov 30, '10 08:29:36PM

This was a major help to me. Thank you!

(My wife's laptop's screen broke, but other than that the computer works fine, so I wanted to set it up as a home server. I could SSH into it. Now with this hint I've been able to use the SSH command-line session to start Screen Sharing; and from there everything is much easier.)



[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: covisp on Jun 20, '11 02:25:33PM

Neither of these locations works for OS X Lion, sadly. It appears that a binary plist is created at /Library/Preferences/com.apple.RemoteManagement.plist, but the contents of it do not seem to change when he setting in Sharing=>Remote Management are changed, nor when Sharing=>Screen Sharing is turned on, but the file's time stamp is changed.

[raw]
<dict>
<key>ARD_AllLocalUsers</key>
<false/>
<key>LoadRemoteManagementMenuExtra</key>
<false/>
<key>ScreenSharingReqPermEnabled</key>
<false/>
<key>VNCLegacyConnectionsEnabled</key>
<false/>
</dict>
[/raw]

There is also /Library/Application Support/Apple/Remote Desktop/Client/Tasks/tasks.plist which is touched, but not actually changed. I suspect all these settings now are 'hidden' in some defaults write area or a database?

Haven't found it yet.


---
http://www.covisp.net



[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: MatteoC on Aug 03, '11 02:39:33PM
for me the following did the job:


cd /System/Library/LaunchDaemons/
sudo launchctl load -w com.apple.screensharing.plist

where

sudo launchctl unload -w com.apple.screensharing.plist would disable it. Worked for me in Lion. Might work in older Versions too.

[ Reply to This | # ]

10.6: Start screen sharing remotely in Terminal
Authored by: mishamazor on Nov 08, '11 10:24:42AM
Great, this is the only one that worked for me under 10.6.6:
sudo sh -c "/bin/echo -n enabled > /private/etc/ScreenSharing.launchd"
How do I rewrite this code to disable screensharing? None of the options on this thread work as yet. Thx, Misha

[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: buttercupp on Sep 17, '09 11:43:28AM

Very cool tip, worked great. Thanks!



[ Reply to This | # ]
10.5: Start screen sharing remotely in Terminal
Authored by: kiezpro on Mar 14, '10 01:02:53PM
Thanks for the hint! I've put together a quick shell script which pretty much works like a Linux start-/stop-script to enable or disable Screen Sharing on my machines. It's quite self explanatory and looks like this:

#!/bin/bash

LAUNCHD_FILE=/Library/Preferences/com.apple.ScreenSharing.launchd

if !( groups | grep -q admin ); then 
	echo "Must be admin to run this script"
	exit 1
fi

case "$1" in 
	status)
		if [[ -e $LAUNCHD_FILE ]]; then
			echo 'Screen Sharing is enabled';
			exit 0;
		else
			echo 'Screen Sharing is not enabled';
			exit 1
		fi
		;;
	start)
		echo -n enabled > $LAUNCHD_FILE
		;;
	stop)
		rm -f $LAUNCHD_FILE
		;;
	*)
		echo "Usage: $0 {status|start|stop}"
esac


[ Reply to This | # ]
10.6: Start screen sharing remotely in Terminal
Authored by: SuperSugar on Feb 29, '12 03:36:10PM

I use this method of activating screen sharing pretty frequently on various snow leopard machines. Having only remote login active is preferable to me. I have found that simply creating the ScreenSharing.launchd file is enough to activate it. So there is no need to echo "enabled" and feed it into the file, simply run this command from root:

$ touch /private/etc/ScreenSharing.launchd or $ touch /etc/ScreenSharing.launchd

/etc is a symbolic link to /private/etc (at least <10.7... not sure about 10.7-10.8) so either path works.



[ Reply to This | # ]