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