Thursday, December 8, 2011

Graphical connection to a Mac from Linux

For my lab work, I have developed an (almost) cross-platform program based on Qt4 that help us analyze our data. One of the motivations to use Qt was the ability to port the program to other platforms, and in particular MacOSX (half of my team uses them). After installing the required development tools using MacPorts (mind you, the MacOS version of the development tools, not the X11 one), I was able to compile and run the program without a single code change on my bosses' Mac. But here come problems: several things do not work the same way in Mac and in Linux (whereas it should, I think), so additional tweaking and debugging will be necessary.

This is where the problem comes in: I don't own a Mac and don't intend to, so I need to connect to my bosses' Mac in order to perform testing. How can I connect to a Mac display ? X11 connection won't work, since my application is a Mac application and not a X11 one. I had him turn on screen sharing (the most basic tick box), which sets up a VNC server on the Mac. Unfortunately, when I connect using the command-line VNC clients available for debian, ie vncviewer (from the packages xvnc4viewer or xtightvncviewer), I get the following problems:

~ vncviewer chrismac

VNC Viewer Free Edition 4.1.1 for X - built Mar 10 2010 22:31:05
Copyright (C) 2002-2005 RealVNC Ltd.
See for information on VNC.

Wed Dec  7 10:40:41 2011
 CConn:       connected to host chrismac port 5900
 CConnection: Server supports RFB protocol version 3.889
 CConnection: Using RFB protocol version 3.8
 CConnection: No matching security types
 main:        No matching security types

The good news is that remmina is able to connect graphically, although for me it required that I set the display depth to 24 bits (else it seems to connect, but the connection dies immediately). Great, I'll be able to debug, then...

Edit: after a while, I found out that remmina had some drawbacks when connecting to a Mac, such as, at least in my case, a weird problem with Shift: once I hit Shift, I'm never able again to type in lowercase characters, which is quite painful. I tried also Vinagre, who handled that better (but had some quite painful freezing moment), so I must say that I finally found a client I'm happy with: gtkvncviewer.


Bruno BEAUFILS said...

Seriously I would not trust screen sharing (which is just a sort of VNC connection if I understand it well).

In order to connect to my parent's Mac from my Linux box I use vnc over ssh :

* I opened the ssh sharing on their MacOS X

* I installed a VNC Server on their MacOS X

* Each time I need to connect to the Mac host :

1. I establish a ssh tunnel from my Linux host to their MacOS X

2. I start a VNC server on the Mac host via ssh

3. I use xvnc4viewer in order to contact the VNC server through the ssh tunnel

On my host I use the following bash function to simplify the process (added in my $HOME/.bashrc)...

vnc_host ()
# $1 = user@hostname
user=$(echo $1 | cut -d @ -f 1)
host=$(echo $1 | cut -d @ -f 2)

ssh ${user}@${host} startvncserver

VNC_VIA_CMD='ssh -f -L "$L":"$H":"$R" "$G" ; sleep 20' xvnc4viewer -FullScreen -PreferredEncoding=ZRLE -via ${user}@${host} localhost

ssh ${user}@${host} stopvncserver

...which uses the two following functions added in the $HOME/.bashrc of the Mac OS X :

function startvncserver ()
launchctl submit -l vncserver -o /tmp/vncserver.log -e /tmp/vncserver.log -- /Applications/Utilities/Vine\ -rfbnoauth -disableScreenSaver -keyboardLoading yes -pressModsForKeys yes -localhost
sleep 2
function stopvncserver ()
launchctl remove vncserver
rm -f /tmp/vncserver.log

mahasiswa teladan said...

hi...Im student from Informatics engineering nice article,
thanks for sharing :)

Chris Wilson said...

Thanks for the recommendations, I now need to manage Macs remotely and had a lot of trouble finding a client that works reasonably well over low bandwidth.