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 on which you want to enable VNC.

EDIT 2/23/2017: If you don’t want to enable Apple remote management, but instead ONLY want to enable screensharing, use the two commands below in Terminal:

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. This will enable Apple Remote Management:

 

THE FOLLOWING INSTRUCTIONS ARE DEPRECATED:

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

 

Enter your administrator password if requested.

Then, navigate to /Library/Preferences/

 

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

 

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

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

 

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

 

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

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

 

and copying and pasting the following text:

 

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

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

 

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

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

 

Finally, let’s reboot the machine:

 

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.

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

  1. 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.

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

  3. Pingback: the blogging » It’s tough to use a computer with no display

  4. 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.

  5. Pingback: Ryan’s Tech Notes » Blog Archive » Enabling Remote Access to Apple OS X Leopard via SSH Command Line

  6. 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

  7. 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

  8. Pingback: links for 2010-02-05 (Jarrett House North)

  9. Pingback: VNC OS X - przyda?o si? :) - rostman.pl

Leave a Reply