Project

General

Profile

Using VNC Connections on the novagpvms

Courtesy of Dominic Brailsford, who wrote this instructions for the dunegpvms, which have been adapted here for the novagpvms.

VNC provides you with a remote window to easily view GUIs from a remote machine with very little delayed response.

You need to do a few things prior to following the rest of the instructions:
  • Pick a number for your VNC server (Pick any number between 0 and 99 -- in this example I'm going to use 22)
  • Pick a novagpvm that you like to work on (I'm going to use novagpvm06 in this example)
  • Install a VNC viewer on your local machine

On your chosen novagpvm (i.e. ssh to it)

Firstly, check whether your chosen VNC server number is available. Run the following on the command line (change the 22 to the number you picked - do not forget the -localhost option. If you do, then your VNC session will be automatically killed by a cron job set up to detect these.):

vncserver :22 -localhost -bs

It will tell you if the VNC server already exists; pick a different number in that case and test again. If the specific server does not exist then it will be created (it may ask you to pick a password, remember it for later).
Add the following snippet to the bottom of your $HOME/.profile or $HOME/.bash_profile (open either in a text editor). Again, change the 22 to your VNC server number.

#VNC stuff
VNCNUM=22 #CHANGE THIS NUMBER TO WHATEVER VNC SERVER NUMBER YOU PICKED
if [[ `hostname` == *"gpvm"* ]] #only start VNC servers on the gpvms (i.e. not on the build machines)
then
  export DISPLAY=localhost:$VNCNUM #Export the display to point to the VNC server
  if [ `lsof -i -P -n | grep $(expr 5900 + ${VNCNUM}) | wc -l` -eq 0 -o `lsof -i -P -n | grep $(expr 6000 + ${VNCNUM}) | wc -l` -eq 0 ]
  then
    echo "vncserver :$VNCNUM not running.  Starting now...." 
    vncserver :$VNCNUM -localhost -bs    #Check if the VNC server is running and start it if not (-localhost mandatory!)
  else
    echo "vncserver :$VNCNUM already running (hopefully owned by you).  Not attempting to start the vncserver..." 
  fi
fi

On your local machine (i.e. open a new terminal window and do not ssh anywhere)

Add the following snippet to the bottom of your $HOME/.ssh/config. Change essmith to your own kerberos principal, change the two occurrences of novagpvm06 to whatever novagpvm you chose at the start and change the 22 to your VNC server number (if your VNC number is between 0 and 9 then include a preceding 0 e.g. 00, 01, 02 etc.)

Host novagpvm06
  HostName novagpvm06.fnal.gov
  User essmith
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes
  GSSAPIAuthentication yes
  GSSAPIDelegateCredentials yes
  LocalForward 5901 localhost:5922

This snippet does a couple of things. Firstly, it allows you to connect to your chosen novagpvm without specifying your kerberos principal or the full address of the gpvm. In the case of the above snippet, the following ssh command connects me to novagpvm06

 ssh -Y novagpvm06

Secondly, and more importantly, it automatically forwards the remote port used by the VNC server on the novagpvm to a specific port (5901 in the example above - you do not need to change this number) on your local machine.

How to use your VNC server

ssh to your chosen novagpvm using its new shortened name. The ssh connection should automatically handle the port forwarding for you in the background. Now fire up root and open a TBrowser as a test.

On your local machine (open a new terminal window and do not ssh anywhere), open your vnc viewer software and point it towards localhost:5901. On a mac, the command is:
open vnc://localhost:5901
If you set a password when originally creating the VNC server on the novagpvm, you will be prompted for it. Hopefully you now see the TBrowser.
To use VNC from now on, you should only need an active ssh connection to your chosen novagpvm (e.g. when you're working on it) and a VNC viewer open and pointing to localhost:5901 on your local machine.