VNC over SSH

VNC over SSH

Setting up VNC server


  • Never use root user to start your VNC server
  • Always login as SysAdmin or a power user account to start your VNC server
  • You may want to tweak xstartup script under .vnc of your home directory for VNC server start up
  • For example:

TightVNC server on Ubuntu

  • Checking whether your TightVNC server Xtightvnc is up

  • If VNC server is already running, the terminal message will return something like the following.

  • If VNC server is not running yet, the terminal message will just return grep command message.

For CentOS

Starting VNC server

  • To start tightvncserver or vncserver, execute the following command as SysAdmin (NOT as root)

  • If it is the first time using vncserver command, you will be prompted to enter VNC display password and viewer only password. Do set the display password now but you can alter later with vncpasswd.
  • You may want to write a short shell script for shortening above command. This is optional.

  • Stop/Kill tightvncserver

  • Note that where :1 is screen display number. You may change this display to some other number of your choice.
  • To set/reset VNC display password

Connecting VNC client through SSH Tunneling/Port Forwarding

On Mac/Linux

  • This section is to be done at client computer, laptop or workstation that connect to VNC server.
  • You will at least require VNC viewer application in your client machine.

Method 1

  • On Mac, GNU/Linux and BSD, use the following SSH command to connect your VNC server

  • Now the ssh connection shall be forwarded to your localhost machine’s port 5901
Mac User
  • Mac user can download and use Chicken of the VNC
  • At host field, enter localhost
  • At display field, enter 1. Take note display number should tally with your vncserver setup.

Method 2

  • If you can have vncviewer command, you can use -via to connect your VNC server.
  • This is normally on GNU/Linux

  • Note that where :1 is display number which should tally with your VNC server start up.
  • After executed above command, the vncviewer GUI client will be launched automatically and you will be asked for VNC display password.

On Windows

  • Start PuTTY new session with your IP

  • At PuTTY navigation nodes, goto Connection > Tunnels. At source port field, fill 5901 (or port number which your VNC server listener on). At destination field, fill localhost:5901. You may play around with port number, this is your current local machine port. Make sure which ever port you’ve chosen should be free/available.

  • If satisfy with above setting, press add button.

  • Now go back to Session node, give session name to save the session setting.

  • Pressing save button will save these setting.

  • Finally, you may press open button to start your normal PuTTY SSH connection to your server. Supply your login name and password to login as per normal.

  • Next, start your favorite VNC viewer.

RealVNC Viewer

  • At server field, enter localhost:1.

  • Your VNC display password.

TightVNC Viewer

  • At server field, enter localhost:1.

  • Your VNC display password.

Take note, :1 denote 5901 of your localhost port. So, 5092 for :2 and so ford.