Friday, November 26, 2010

Remote Desktop Into Mac OS X Leopard From Windows

SkyHi @ Friday, November 26, 2010

Using remote desktop, you can access one computer from another computer through the internet or a local area network. Here, I’ll outline how to remote desktop into Mac OS X 10.5 (Leopard) from Windows, which is something I had to do today.

On the Mac, go to System Preferences > Sharing and check “Remote Login,” if it is unchecked. You may get a message saying that your current power settings will not allow remote login when the Mac is sleeping. Just hit OK for that and Take note of the example ssh command given in the information area.

Then check “Screen Sharing,” if it is unchecked. Click the “Computer Settings” button on the right. A prompt should appear. Check “VNC Viewers may control screen with password” and type in a memorable password. Then hit OK and uncheck “Screen Sharing.” This is a security precaution. You will turn this on later when you ssh in.

On your PC, you will need to install PuTTY and TightVNC. You can get PuTTY here: http://www.chiark.greenend.org.uk/~sgtatham/putty/ and TightVNC from here: http://www.tightvnc.com/download.html.

On your PC, open up PuTTY, and in the “Host Name” field, type in the host name of the computer. This is the text after the @ symbol in the provided ssh command example noted earlier, e.g. my.host.name.edu. Select SSH as the connection type.

Then, on the left category menu, click on Tunnels, which is under Connection > SSH. For the “Source Port” box, type 5901, and for the “Destination” box, type localhost:5900. Then hit the Add button. And then hit the Open button in the bottom-right.

A black window will appear and a prompt may appear, asking you whether you trust the host. Click yes. Then, in the black window, you will be asked for your login name – enter your Mac login name. Then it will prompt for your password – enter that too.

Then, enable Screen Sharing by entering the following commands into PuTTY:
cd /Library/Preferences
echo -n enabled > com.apple.ScreenSharing.launchd
Next, open up TightVNC Viewer on your PC. It will prompt you for a VNC Server. Enter localhost:1. (This is possible because you are tunneling Port 5901 through SSH.) Hit "Connect." You should then be prompted for a password. Enter the VNC password that you set earlier.

That's it! A window should appear on your PC with the exact same display as your Mac and you should be able to control the mouse and do most things remotely.
Unfortunately, this method can yield severe lag between the two computers, especially if your Mac's internet connection has a slow upload speed.

One performance tweak you can do on the Mac is enter into a Terminal:
defaults write com.apple.ScreenSharing controlObserveQuality 3
This changes the quality of the remote display to setting 3 which is 8-bit color. The other settings are:
1 = black and white
2 = grey scale
3 = 8 bit color
4 = 16 bit color
5 = full color

Just replace the "3" in the command with the number of the desired setting.
You should probably also change your mac desktop wallpaper to a solid color and/or reduce the resolution so the screen image is more easily compressed.

Finally, before you close the connection, you should disable Screen Sharing. In your PuTTY window, which you must keep active while you are on VNC, enter the following commands:
cd /Library/Preferences
rm com.apple.ScreenSharing.launchd
Edit: Apparently, removal of this file and disabling of Screen Sharing only takes place after you restart the computer. i.e. after you remove this file, you can still vnc into the system. However, I don't know whether you can still vnc into it from a computer different from the one from which you originally vnc'd. You can restart the system immediately (closing all open files without saving changes) with:
sudo shutdown -r now
And that's it! You should now be able to remote desktop into Mac OS X Leopard securely from a Windows machine. Happy remote desktop-ing! Also, please leave a comment below if this was helpful or if you have any questions.

Note: If you have Cygwin installed like I do, then you can just open up a Cygwin shell window and enter:
ssh username@hostname -L 5901:localhost:5900
to ssh in with port forwarding.

Note 2: If you want to be able to access your Mac anytime, go to Energy Saver, which is also in System Preferences, and move the slider for Time Before Sleep to Never. You can also schedule automatic turn on/off of the Mac to save energy, e.g. have it off while you're asleep.

References:
http://lifehacker.com/319528/remote-control-leopard-with-tightvnc
http://www.macosxhints.com/article.php?story=20080318190503111
http://www.alternapop.com/2007/12/01/leopard-screen-sharing-image-quality/
http://www.whenbrainsfly.com/2009/01/remote-desktop-into-mac-os-x-leopard-from-windows/