Remote Control of OS X (Tiger) Desktop via VNC

Posted by Dave Minor Fri, 21 Dec 2007 21:25:00 GMT

I’ve been asked to post the method that I use to easily log onto remote macs to facilitate support on some of my client’s machines. This is not rocket science, just my howto that I pieced together from several sources long forgotten (sorry). It’s very possible that this procedure will continue to work on Leopard, all of the machines I deal with are still running Tiger at this point. I think this worked with Jaguar too, but I can’t recall.

The basic idea is to log onto the remote machine via SSH, start a VNC server, then connect from the local machine and use SSH port forwarding tricks to keep yourself from leaving VNC ports open and forwarded on the remote router.

Remote Machine Setup

  • must have an administrator’s account
  • must have a static IP address on the LAN
  • install OSXvnc which is now called something else. I am running version 1.4. I’m not sure if this will work with the new server
  • create a ~/bin directory
  • in ~/bin, I have two files:
dminor$ cat bin/startvnc 
#!/bin/sh
sudo /Applications/OSXvnc.app/OSXvnc-server -rfbport 5900 \
> ~/Library/Logs/OSXvnc-server.log 2>&1 &

echo "VNC has started" 

dminor$ cat bin/stopvnc 
#!/bin/sh

sudo killall OSXvnc-server
echo "VNC has stopped" 
  • locally, run bin/startvnc and bin/stopvnc to make sure they are working properly and that they are firing off the osxvnc server
  • in ~/.bash_profile, just under my path, I put source ~/bin/startvnc and as the last line of the file, trap '$HOME/bin/stopvnc' 0
  • now when you start a terminal sesssion (locally or SSH), the vnc server will start.
  • verify in Sharing Pref Pane that the Remote Login service is checked and that you can SSH into the box.

Remote Network Setup

You’ll need to have port forwarding on the network’s router to the remote machine on port 22. As you’ll see below, there is no need to have VNC ports forwarded on the router.

Ease of Access via Hostname

It sure makes it a lot easier if you can SSH to a hostname that stays constant instead of having to determine the dynamic IP address of the remote machine each time. For dynamic IPs, I use dyndns.org to maintain a good hostname. For static IPs, I just setup an A record in the DNS zone file. Actually, if it’s a dynamic, I usually setup a CNAME record pointing to the dyndns hostname. And this works great on a local network too with bonjour.

Local Machine Setup

On your local machine, you need SSH and a VNC client. On OSX, I use Chicken of the VNC.

In my ~/.ssh/config file, I’ve setup entries for each remote machine like:
Host jkmini
  HostName jkwork.clients-domain.com
  Port 22
  Compression yes
  LocalForward 5901 127.0.0.1:5901
Now when I SSH jkmini, I get a terminal and vnc starts automatically. Here’s a sample session on the local network:
[dminor@ginger: ~]$ ssh sarahs-imac.local
Last login: Fri Dec 21 15:54:35 2007 from ginger.local
Welcome to Darwin!
VNC has started

[dminor@Sarahs-iMac: ~]$ ps aux | grep vnc
root     21718   0.0  0.2   196736   2680  p2  S     3:55PM   0:00.17 /Applications/OSXvnc.app/OSXvnc-server -rfbport 5900
dminor   21721   0.0  0.0    27812      4  p2  R+    3:55PM   0:00.00 grep vnc

[dminor@Sarahs-iMac: ~]$ logout
VNC has stopped
Connection to sarahs-imac.local closed.

In the case of a controlling a local machine (as above), I’d simply fire up Chicken of the VNC and connect to the hostname.local on the proper port (5900 here) and gain access.

On a remote session over SSH, you’ll see that we setup local port forwarding on the SSH session, so locally, port 5901 is being redirected to 5901 on the remote machine over SSH. I fire up Chicken and connect to localhost:5901.

Multiple Remote Machines That Share a LAN

I’ve also configured multiple machines behind the same router (therefore a shared public IP). I can attach to two machines on the same LAN at the same time over SSH with no problems. I may post that additional writeup one day.

I hope this is helpful and not too confusing.

Posted in , ,  | 2 comments

Diff a Tree and Copy

Posted by Dave Minor Mon, 05 Mar 2007 20:32:00 GMT

When maintaining older projects that don’t have deployment scripts written and where production is not under version control, I find a lot of times that I need to diff the two directory trees looking for which files have changed and then copy them to production.

Today I had a bunch of those to do. I worked up a shell one-liner that will handle this and I’m posting it here to remember the next time this comes up.

diff -q -x .svn -r . ../production_root | awk '{print $2}' | xargs -i -t cp {} path/to/production_root/{}

Let me know if you see a better way.

UPDATE: ok, so this totally fails when there are files in the current tree that don’t exist in the production_root because my awk outputs ‘in’ instead of the filename.

I guess I really need to suck it up and implement a capistrano deployment system for my non-rails apps.

Posted in ,  | no comments

Spam, not just for lunch anymore

Posted by Dave Minor Mon, 28 Aug 2006 15:53:00 GMT

Tim Bray says:
I don’t know about you, but in recent weeks I’ve been hit with high volumes of spam promoting penny stocks. They are elaborately crafted and go through my spam defenses like a hot knife through butter.

I feel your pain Tim. I, too, have been hammered with spam in recent weeks. I actually spent a good part of the day Friday tweaking my spam settings to try to pick up more. I think I did some good. For most of Friday, Saturday, and Sunday, very few messages made it to my mail client. Then this morning, there were a dozen or so. :(

Posted in ,  | no comments

Phase One: Complete!

Posted by dminor Thu, 04 Dec 2003 19:03:00 GMT

After a couple of weeks of trying and trying and trying, I just finished the first step in setting up my new server. I built a box that includes a Supermicro X5DPA-TGM motherboard with Intel 7501 chipset and the IC5H SATA controller and 2 120GB SATA drives. The challenge became finding a linux kernel that would see the SATA drives so we could install to them and boot from the them. Doug has more information about the process of this phase and I’ll add any comments I have to that page. Just wanted to put it here so that someone will have an easier time finding the information.

Posted in  | no comments