Set up Screen Sharing (VNC) via command line on Mac OS X remotely using SSH


Locked out of a Mac because Remote Desktop has suddenly taken a crap on you? Want to remotely enable Screen Sharing (Apple’s fancy name for VNC)? Well, as long as you have SSH active, you can enable Screen Sharing on Mac OS X 10.5 by following these easy instructions.

SSH into the machine you want to enable VNC on.

EDIT 2/12/2009: Thanks to David Jones for pointing out a document from Apple which details a command-line equivalent to all the steps detailed in my original post. Instead of the original directions posted here, simply execute the following command after SSHing into the target machine in order to enable screen sharing for the admin user and restart ARD:

$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent -menu

THE FOLLOWING INSTRUCTIONS ARE DEPRECATED:

First, we need to make sure that Remote Desktop is turned OFF. Issue the following command:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop

Enter your administrator password if requested.

Then, navigate to /Library/Preferences/

cd /Library/Preferences

We’re going to create three text files there, which set up the preferences for Remote Management and VNC.

sudo tee com.apple.RemoteManagement.plist

Enter your administrator password. Then, copy and paste the following text:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">
<dict>
<key>ARD_AllLocalUsers</key>
<false/>
<key>LoadRemoteManagementMenuExtra</key>
<true/>
<key>ScreenSharingReqPermEnabled</key>
<true/>
<key>VNCLegacyConnectionsEnabled</key>
<true/>
</dict>

</plist>

Press return, then press CTRL-d to close the file.

sudo tee com.apple.ScreenSharing.launchd

Enter your administrator password if prompted. Then, copy and paste the following text:

enabled

Press return, then press CTRL-d to close the file.

Set the default VNC password to “pass” by creating this file:

sudo tee com.apple.VNCSettings.txt

and copying and pasting the following text:

6755221D8BA8C5E2FF1C39567390ADCA

Press return, then press CTRL-d to close the file.

Let’s change the ownership and permissions on these files to their correct values:

sudo chmod 644 com.apple.RemoteManagement.plist
sudo chown root:admin com.apple.RemoteManagement.plist
sudo chmod 644 com.apple.ScreenSharing.launchd
sudo chown root:admin com.apple.ScreenSharing.launchd
sudo chown root:wheel com.apple.VNCSettings.txt
sudo chmod 400 com.apple.VNCSettings.txt

Let’s set up launchd to automatically launch Screen Sharing on startup:

sudo echo enabled > /Library/Preferences/com.apple.ScreenSharing.launchd

sudo bash -c 'echo enabled > /Library/Preferences/com.apple.ScreenSharing.launchd'

Finally, let’s reboot the machine:

sudo reboot

You can now VNC into your Mac, using either Leopard’s built in screen sharing or a third party VNC utility. On Mac, I recommend Chicken of the VNC, available for free download at http://sourceforge.net/projects/cotvnc/. Point your app of choice to your machine’s IP address or hostname. When prompted for a password, use the default one from above (pass).

Once you’re in, you need to go to System Preferences -> Sharing -> Screen Sharing, and click the “Computer Settings” button. There, enter in a new password to replace the default used at the beginning steps of this article.

About this Piece O' Garbage

Join the fray by contributing trash, feeding on other people's trash, or linking to it from your dump.


Other Garbage Nearby

Talk Some Trash

Take a moment to submit some trash to this garbage pile. Some basic HTML is allowed for formatting.

Reader Trash in this Garbage Pile

This worked for me.

The only thing that’s wrong is the use of the sudo echo enabled > “” command – sudo will run the echo as root but bash won’t have permission to rewrite the file. Change to tee like the above examples.

@Mark: Good catch. Thanks for sharing. I’ve modified the original article to reflect your comment.

[...] the meantime, I jumped through some hoops to enable Screen Sharing via the command line. Chris Brewer’s instructions were the most thorough, but after following them I had to try a couple of different [...]

Thanks so much for this. Worked a treat. I didn’t want to reboot my Mac, though, so a bit more searching on the net (and a bit of extrapolation) produced this command:

sudo /bin/launchctl load /System/Library/LaunchAgents/com.apple.ScreenSharing.plist

…which started up the VNC server without rebooting. I’m in via TightVNC from my windows box at work. Pain in the rear fighting with the screen saver to log in though. Eventually got it.

Activate Remote Desktop Sharing, enable access privileges for all users, restart ARD Agent:

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

Read: http://support.apple.com/kb/HT2370

[...] you need it, and then turn it off when you’re done.  Also, the write-ups of Tim Boland and Chris Brewer were very helpful in figuring this [...]

For some reason my kickstart (ARD) & associated files got hosed – so the Apple method was useless. This method works fine except no “>” required

sudo bash -c ‘echo enabled /Library/Preferences/com.apple.ScreenSharing.launchd’

allowed me to use Chicken of the VNC and correct the ARD issues

Hey Brewer – good write-up. My mac’s graphics card appears to be dead, and I searched around looking for exactly this. How cool that it turned out to be your article. talk at ya on FB soon – Orstead

[...] Garbage In Garbage Out : Tech Blog – » Set up Screen Sharing (VNC) via command line on Mac OS… Interesting tips for making a headless Mac headful. (tags: macosx macmini) [...]