Linux – VNC via SSH with a single command

linuxUbuntuvnc

I have a VNC server (x11vnc) configured to allow me to log into the machine at the local display (:0) via SSH tunnel, following the instructions here.
My question: is there a way to create the tunnel AND launch vncviewer with a single command/script?

Here's how I'm launching x11vnc from /etc/gdm/Init/Default:

x11vnc -localhost -nopw -ncache 0 -o /var/log/x11vnc.log -forever -bg

Edit: please note that in this way x11vnc starts from gdm, so that I can log into the local session myself.

(Server and client: Xubuntu 9.04)

Best Answer

The vncviewer can connect on it's own through SSH, so a shorter command would be:

vncviewer -via username@hostname.tld localhost:x

On the above, x is your local display (0, 1...).