Keep In Touch

Tune in to your Linux laptop anytime from an iPhone or iPod Touch – or adapt this technique to reach your system from other mobile devices.

Like many, I have a laptop. Also like many, I have a girlfriend who wants to use my laptop, so I created an account for her in Ubuntu Jaunty; she can use the "switch user" session feature in the upper-right corner whenever she wants to log in. Now she has her desktop, and I have mine. However, sometimes I need to use the system at the same time she is logged on.

When she is using the system, I turn to my iPod Touch for computing tasks. The Touch starts faster than a conventional PC. I can check my mail, browse the web, and even play a game or two to make the time pass while she rearranges her MP3 collection. But some problems still require a full computer system. For instance, I have an account on a torrent site, and that connection must go day and night or I'll lose the account. Also, I need to convert the downloaded movies from XviD to MP4 with HandBrake, a CPU-hungry application that requires real PC hardware.

The ideal solution is to work from my iPod when I can, then connect to the laptop when necessary through a remote session using the iPod as a remote VNC client. To make this system work, I need to connect to a VNC server running in the background on the laptop – without the need for a separate SSH session to start the server manually. Also, it is important for this VNC connection to be invisible to the user logged on to the laptop – I want my own desktop, not a view of the current desktop session – and the connection must continue unhindered, even if my girlfriend switches the local desktop to her own account.

In this article, I describe a technique for remote connection to a Linux laptop or desktop system from an iPod Touch. The instructions for an iPhone are similar, and some variation of technique will work for almost any handheld system that has a VNC client and is capable of participating in a local wireless network.

Setting Up the Client

The first task is to install a VNC client on an iPod Touch, iPhone, or similar device. I use Jaadu VNC [1], which I have found to be one of the best VNC apps for Apple devices. At US$ 24.99, Jaadu is pricier than other similar VNC options, but it also offers some unique options that are specifically tailored to the iPhone's small screen, such as special buttons to mimic a Ctrl+Alt+Delete command, saved servers, support for high resolution, and customer support. Setup is fairly easy: Just install Jaadu VNC through the Apple Store; input your VNC server's IP address, username, and password (Figure 1); and the rest is done by the application, which automatically connects and offers to bookmark your servers. If you want to use Jaadu VNC as a view-only solution, you can even turn off the virtual mouse and keyboard. If you don't like Jaadu VNC, you can use one of the alternative VNC clients available for the iPhone, such as RealVNC, Vnsea, or Mocha VNC Lite.

Figure 1: Pre-configuring a server connection in Jaadu VNC.

Performance Matters

The higher you set the refresh rate of the VNC server and client, the more CPU your PC will use. This same principle also applies to the number of colors you want to view: The more colors you chose to use for a perfect image on the viewing end, the more your CPU readings will increase. VNC technology works by sending sequences of screenshots. Practically each time a connection is established with x11vnc, your PC will start taking screenshots and sending them through the network in an attempt to form a flowing screencast of the respective images.

This will also consume some of the bandwidth. If you plan to use Jaadu VNC, note that you can change the refresh rate and number of colors to be displayed directly from the application. If the application you plan to use does not have such settings, you can specify them on the server end. For the refresh rate, use -xrefresh yy, where yy is the rate in seconds. To stabilize colors, use the -8to24 or -24to32 arguments for better performance. If these options still don't satisfy your needs for a perfect balance of quality and quantity, consider using the nice command in combination with x11vnc to run the VNC server with a modified scheduling priority – for example: nice -n 20 x11vnc -many -rfbauth /home/user/.vnc/passwd -find.

The Server Side

The next step is to configure a VNC server on your Linux PC. The goal is to set up a VNC server that will run in the background and let the remote user create a separate session that is independent of the current desktop user. For this article, I will use the x11vnc VNC server, which is available from the project website [2]. Also, you will find x11vnc in the repositories of many popular Linux distros. Most VNC servers launch a separate X Server session at startup; however, x11vnc has the ability to connect to an existing X Server session. This feature means you won't need to consume memory launching a new session. It also means all your open applications will be available right away to the VNC client: You can continue without the need to save and re-open your work.

If you are working on a Debian-based system, you can install x11vnc on your laptop or PC:

sudo apt-get install x11vnc

The goal is to make x11vnc start automatically at boot so you won't have to SSH from the iPod Touch to the laptop and manually start the server. To make x11vnc autostart, place it in an rc.local file. Or, you can use the native tools of the Linux desktop to configure x11vnc to start with the system. In Ubuntu, for instance, choose System | Preferences | Startup Applications and click the Add button to enter a command for starting xllvnc (Figure 2). Place the x11vnc startup string in the box labeled Command. When you start the system, first the X server will start, then Gnome will start, then x11vnc will launch to display a fresh new X server (Figure 3).

Figure 2: Configuring Ubuntu to launch x11vnc at startup.

Figure 3: The x11vnc session from the VNC mobile client.

Security First

If you're paranoid, or if, by any chance, your wireless router is not as secure as you wish it would be, you'd better set a password to connect to x11vnc. This password will also come in handy if you're not connecting through the local network but are attempting to access the server through the open Internet. (A remote connection from beyond the LAN will, of course, require additional considerations regarding firewalls, open ports, and other perimeter security issues.)

To set a password for x11vnc, use vncpasswd, which is found in the tightvncserver package residing in Ubuntu's default repositories. The vncpasswd command will prompt you twice for a password, which will be stored and encrypted in ~/.vnc/passwd.

X11vnc must keep running even after the client VNC application logs out. By simply launching x11vnc with no arguments, the VNC server will shut down immediately after you close the client. Use the -many or -forever argument to keep the server listening for connections.

Because I don't want other people peeking at my desktop through the wireless network with other VNC clients, I'll use the -rfbauth option so that x11vnc will prompt for the password each time I log in.

By now, the command looks something like:

x11vnc -many -rfbauth /home/user/.vnc/passwd

To make sure x11vnc won't use the local user's home path, you must specify the full system pathname to the password file.

Related content

SSH can make you crazy if the WLAN connection keeps breaking down, the IP address changes, or the data packets trickle over a slow mobile connection. AutoSSH and Mosh offer some features you won’t find in ordinary SSH.