VNC over SSH in Ubuntu 8.10 (Ubuntu to Ubuntu)

This procedure describes how to set up and connect to a VNC server over an SSH tunnel from one Ubuntu machine to another. I am making the assumption that an SSH server is already running on the host machine, and that the host is running Kubuntu. It shouldn’t be hard to figure out the equivalent autostart directory for GNOME, but for newer versions of GNOME I believe it’s in the ~/.config/autostart/ directory.

Credit goes to ubuntuguide.org and ubuntu-tutorials.org for almost all these details.

On the host (the machine which will be running the VNC server):

Install the VNC server:

$ sudo apt-get install x11vnc
$ mkdir ~/.vnc

Create the VNC server’s password file (substituting a plaintext VNC login password for YOUR_PASSWORD):

$ x11vnc -storepasswd YOUR_PASSWORD ~/.vnc/x11vnc.pass

Now create an autostart file that will run each time. For newer versions of GNOME, the path should be to a filename of your choosing in the directory ~/.config/autostart/ but I can’t promise that unless someone verifies it for me. For KDE, the path can be exactly as shown below:

$ nano ~/.kde/Autostart/x11vnc.sh

Add the following lines:

#!/bin/bash
/usr/bin/x11vnc -rfbauth ~/.vnc/x11vnc.pass -o ~/.vnc/x11vnc.log -loopbg -display :0

Save/exit the text editor, then make the autostart file executable.

$ chmod +x ~/.kde/Autostart/x11vnc.sh

Run the autostart file (or reboot the machine) to start the VNC server:

$ ~/.kde/Autostart/x11vnc.sh

Now, on the client machine:

Install a VNC client:

$ sudo apt-get install xvnc4viewer

Here we make the assumption that the host SSH server is running on the default port (22). Now type the following command and you should enter a VNC session, after being prompted for the user login password and then the VNC login password (substituting the proper username for “user” and IP or domain for “host”, but “localhost” is literal, do not change it):

$ vncviewer -via user@host localhost:0

In the event that the host is running its SSH server on port XYZ instead of port 22, you may use the following command, with the same caveats as above:

$ vncviewer -via "user@host -p port" localhost:0

(Can someone unit-test this for me? I’m lazy and did most of this from memory.)

MAGIC 8O

December 25, 2008 • Posted in: Linux

Leave a Reply

You must be logged in to post a comment.