Skip to content
Shawfeng Dong edited this page Nov 6, 2016 · 3 revisions

Oftentimes we need to run a GUI program remotely, on Hyades or Eudora, for example. We usually use X Forwarding over SSH to run the X11 program remotely. However, if our network connection to the remote host is slow or over long distance, it is often faster to use VNC to serve a complete X11 session. Here we show you how to run VNC on Hyades or Eudora – you might find the instructions applicable to other scenarios as well.

Install a VNC viewer on your local computer, if you haven't done so already.

I recommend the VNC viewer by RealVNC, which can be downloaded at https://www.realvnc.com/download/

Note

Mac OS X actually has a VNC client built in. The application is located at "/System/Library/CoreServices/Screen Sharing.app", which can be either directly evoked, or evoked though Safari by supplying the URL of the VNC server to the address bar. Unfortunately, OS X's built-in VNC client does not work well with the VNC desktops on Hyades or Eudora! if the window manager of the VNC desktop is twm or mwn, the VNC client doesn't take keyboard nor mouse inputs, for reasons to be determined.

Log onto the remote host using SSH, e.g.:

ssh -l YourUsername hyades.ucsc.edu

Start a VNC desktop on the remote host.

On both Hyades & Eudora, TigerVNC server is installed. Choose a display number N (we'll use 10 in this article) and start the VNC server Xvnc:

$ vncserver :10

The very first time you run vncserver, it will ask you to provide a password (which is different from your account password on the remote host), an obfuscated version of which will be stored in $HOME/.vnc/passwd. You can also run vncpassword to create or modify $HOME/.vnc/passwd.

You can list your TigerVNC server sessions with:

$ vncserver -list

Sometimes a VNC desktop may be already running on the display of your choice, then you'll get an error:

$ vncserver :10
A VNC server is already running as :10
in which case just choose another display number and run vncserver again.

Forward the TCP port TigerVNC server is listening to.

VNC listens to TCP port 5900+N, where N is the display number. However, the VNC protocol (RFB protocol) is not secure; and those ports are blocked by firewall. So you can't reach the VNC server directly, e.g.:

vnc://hyades.ucsc.edu:5910

To get around it, you can forward the port to your local computer using SSH. One way is to start anew an SSH session with local port forwarding, e.g.:

ssh -l YourUsername -L localhost:5910:localhost:5910 hyades.ucsc.edu

Note SSH Local Port Forwarding:

  • The first localhost in -L localhost:5910:localhost:5910 is relative to your local computer and is your local computer in this example; the second localhost is relative to the remote computer and is Hyades in this example. The command above means to forward TCP port 5910 on Hyades to TCP port 5910 on your local computer.
  • The first localhost is often omitted in examples found on the web, which is a mistake and a security hazard! Its presence makes the TCP port to be bound for local use only on your local computer; its absence will make the port available from all all interfaces on your computer. If you computer doesn't filter those ports and your VNC password is simple, both of which are often the case, a malicious hacker can connect to the VNC server via vnc://YourComputer:5910 and thus gain access to the remote host!
  • If your connection is very slow, you can add the SSH switch -C to request compression of all data. On fast networks however, compression will only slow things and should be avoided.
However, you don't need a new SSH session to enable port forwarding, you can use SSH Escape Sequences to enable port forwarding in your existing SSH session. Press the Enter key (to make sure the escape character is at the beginning of a line), then type ~C (tilde and capital C) to open a command line (started with the prompt ssh>), then specify the port forwarding, e.g.:
ssh> -L localhost:5910:localhost:5910
Press the Enter key again to return to your SSH session. The local port forwarding is now established.

Now on your local computer, you can use your VNC viewer/client to access the VNC desktop:

vnc://localhost:5910

Kill the VNC desktop when you are done, e.g.:

$ vncserver -kill :10

xstartup

The $HOME/.vnc/xstartup script is run by vncserver and usually specifies a window manager and some applications that are run by default on any VNC desktop.

twm

On Hyades & Eudora, I've modified /usr/bin/vncserver (a Perl script) such the it will produce the following default xstartup:

#!/bin/sh

[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

The default xstartup uses twm as the window manager. twm is standard window manager for the X Window System and is very lightweight. Although its interface is different from modern common X window managers which tend to mimic Mac OS X or Microsoft Windows, it is simple enough to be mastered within minutes.

If you don't like twm, feel free to modify your $HOME/.vnc/xstartup to use another window manager.

mwm

mwm is the window manager for Open Motif. If you prefer mvm, use the following xstartup:

#!/bin/sh

[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
mwm &

GNOME 2

GNOME 2 is available on Hyades & Eudora too. I don't think it makes much sense to use the very heavy GNOME in a VNC session. But if you must use it, the following xstartup will suffice:

#!/bin/sh

[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
eval `dbus-launch --sh-syntax –exit-with-session`
/usr/bin/gnome-session &

NOTE for some unknown reason, Mac OS X's built-in VNC client works fine with a VNC desktop running GNOME! However, if the window manager is either twm or mwm, OS X's built-in VNC client doesn't respond to keyboard nor mouse inputs!

Clone this wiki locally