Saturday, May 14, 2011

Remote iDevelopment


Well it's has been a while since my last #iDevBlogADay my last one called Retro 2010 was done on 25th of December 2010 when I decided to leave my spot and give a chance to new bloggers to join. Now #iDevBlogADay is bigger then ever and @mysterycoconut had to come up with a new scheme to be able to let more people join in and share the blogging days.  So now each person blog every 2 weeks and another set of people blog on the alternative weeks, ohhh they are also a new website to see them all : http://idevblogaday.com/.

But today topic is not about this, and no I am not going to talk about Mythlound either (not much to report on this right now, but hopefully soon I will).  But about how to do remote iDevelopment or more specifically how to use your Mac without a monitor...  Why that you ask?  Well shortly in the beginning of the new year my main LCD connected to my Mac Mini a Samsung 22" (SyncMaster 225BW) went into a coma... well it's not fully dead but the back light have issue (I would need to replace capacitor to have it working again).

Also during that period of time I got a brand new laptop for starting to explore XNA 4.0 (Xbox + Windows Phone 7).  And I though maybe they are still hope and that I could connect to my Mac via some sort of VNC.  So after some digging in forums and some hints from @celsiusgs I got a solution that work quite well, so here is the steps by steps to get it working (please note that my Mac is running Snow Leopard and the PC connecting via VNC is running Windows 7).

Setup SSH
This is one of the most critical that you should set up first, as with this you should able to complete all the rest of the set up remotely without having a monitor connected to the Mac.  If you're lucky the SSH server is already activate on your Mac and you don't need to do anything, or if you were like me then I had to painfully try to read the flicking/dark screen blindly clicking around until I get the SSH active (just let say it wasn't easy...).

To accomplish this you need to first go into the System Preferences and then choose Sharing.


Once in the Sharing preference panel you need to make sure Remote Login is "check" and as you can see above even it is not said explicitly this is to allow SSH connection to your Mac.  Then you just need to use your favorite SSH client on your second computer and you should be able to connect with your Mac user account, of course you need to have wrote down the IP address of it ;-) (as for myself I am using the freely available PuTTY which is just a small Windows executable so no lengthy and DLL hell installation problem ;-)).

Setup Remote Management (VNC)
Now that you have SSH up and running on the Mac you first need to connect to it before completing the following series of tasks (which were documented very well by Balt on his post on MacRumors Forums).

First step is to make sure that the Remote Management is not already running before changing the configuration.

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

Which should give you some results like this :

intruder@NeoTokyo[~]$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -stop
Password:
Starting...
Stopped ARD Agent.
Stopped VNC Server.
Stopped RFB Register MDNS
Done.

Once this is done, now it's time to change the configuration and have fun with vi our favorite editor (if you want to edit the files with other editors please be my guest, I wont stop you ;-)).

You will need to go edit the following files that is located in /Library/Preferences :

sudo vi com.apple.RemoteManagement.plist

If the files doesn't exist it will be created and if they are already an existing one just make sure the contents of it is a follows :



ARD_AllLocalUsers

LoadRemoteManagementMenuExtra

ScreenSharingReqPermEnabled

VNCLegacyConnectionsEnabled



Then edit the following file :

sudo vi com.apple.ScreenSharing.launchd

And then make sure it only contains the following :

enabled

Now it's time to set up the password for VNC which will be a default one which you will be able to change later on once you're connected into the Mac graphically.

You do this by editing the following file :

sudo vi com.apple.VNCSettings.txt

And the content of the file should only contain the encrypted password as follows (which is "pass") :

6755221D8BA8C5E2FF1C39567390ADCA

The only remaining steps is to change the security of the files we just changed to make sure they have the right privileges and ownership.

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 chmod 400 com.apple.VNCSettings.txt
sudo chown root:wheel com.apple.VNCSettings.txt

Once all the steps above have been completed succesfully it's now time to turn back on the Remote Management service by doing the following :

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

Which should give you some results like this :

intruder@NeoTokyo[/Library/Preferences]$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent
Password:
Starting...
Activated Remote Management.
Stopped ARD Agent.
Stopped VNC Server.
Stopped RFB Register MDNS
Done.

Setup VNC (viewer/client)
Now it's time to see if all the effort done above really work, so you need to have a VNC client installed on the machine that you will use to connect to the Mac.  As for myself I am currently using UltraVNC 1.0.8.2 which I have configured as shown below.


After you made your connection (you know the IP address of your Mac don't you?) you should be prompted for a password which you simply type in "pass" and then you should be in and seeing your Mac desktop.  It might be a good idea at this time to go back to the System Preference panel and go into Sharing to be able to change the default password from "pass" to something let say a bit more secure ;-).

To set up a new password go into Remote Management and then click Computer Settings... and simply go change the password (sadly limited to 8 characters and only letters + numbers).


Setup World Wide Access and Beyond!
It's has been great to be able to access the Mac remotely to do your favorite iDevelopment in Xcode, but the way the thing has been set up above it's for local network access.  What if you're away from home on a remote island, sitting on a nice sunny beach drinking your pina colada and have a WiFi access?  Well you can still do all do this, with the little help of a router ;-),  I was able to do so and it was awesome (ok minus the island, the beach, sun and pina colada, just sitting on the floor in the guest room of my in-laws ;-)).

First set up the rules of your firewall to make sure they let pass the traffic on port 5900 (the screen below is from D-Link setup).


Then the final configuration to make the whole magic work is to configure a Virtual Servers that will redirect traffic from outside source on port 5900 to your Mac running the VNC server (once again the screen below is from my D-Link configuration).


Then to access your Mac remotely via the vast network that is the Internet you need to use the IP address given by your Internet provider (which normally set in your cable modem, dsl modem).

What lay beyond now that you can a World Wide Access to your Mac doing iDevelopment is what not use one of the iDevice to to do that?  You know iDeveloping your next great title for the iPad remotely from that remote island on a sunny beach by simply using your iPad ;-).  You think this is all madness and impossible... think again... they are already several VNC client available on the iPad that support external keyboard (iTeleport, RealVNC), so you know what that mean ;-).  Yes Xcode on the iPad is here, well almost (they are a few limitation with keyboard support such as not supporting directly modifier keys).

Have fun doing remote iDevelopment and feel free to share your experience about it.


This post is part of iDevBlogADay, a group of indie iPhone development blogs featuring two posts per day. You can keep up with iDevBlogADay through the web site, RSS feed, or Twitter.

No comments:

Post a Comment