Setting Up A VNC Sever

There have been some questions about how to set up a VNC server and access it from home so I put together a little tutorial....

  1. The first thing you need to do is start your own instance of a VNC server. To do this, ssh to the machine you want to run the server on (ie the machine you want to be running your bomb on like sunfire31, or 32). Type 'vncserver' in the terminal. You should get something like the following back:

    sunfire31{mpelle03}51: vncserver
    New 'sunfire31:6 (mpelle03)' desktop is sunfire31:6

    Starting applications specified in /h/mpelle03/.vnc/xstartup
    Log file is /h/mpelle03/.vnc/sunfire31:6.log

    There is a very important piece of information here. sunfire31:6 This means that your vnc server is running on sunfire31 as server number 6. This most likely means that 5 other people have servers running on this machine.

  2. If you are inside the firewall, you can simply open you vnc viewer (like tightvnc) and put in sunfire31:6 as the address of the server. Put in the password you selected when you started the server, and your all set.
  3. If you want to connect from home, its a little more difficult, but still can be done. You need to open an SSH tunnel that allows your vnc viewer at home to access the vnc server inside the halligan firewall. In your ssh client, there should be a section for SSH tunnels. I use PuTTY. In the connection config dialog, in the left pane, go to connection->SSH->Tunnels. This is where you need to enter the port forwading information.
  4. You need to determine which source port and which destination port you need to associate. VNC works starting at port 5900. Meaning that if you have a server running as #6 (as I do above) it will be listening on port 5906. In the destination box, enter sunfire31:5906 (or whichever machine you started the server on, with the appropriate port for the number host you are).
  5. The source port is the port on your local machine that will be associated with the destiantion port. Here you can enter 5901. This means that after you open the SSH tunnel, it will be as if sunfire31:5906 is on localhost:5901. If you want to have more than one vnc connection forwarded, you can set up multiple forwards using 5902, 5903, etc as the source ports for the other connections.

  6. Make sure you click add, to actually add the forwarded port. Also, you probably want to go back to the session options and save your configuration so you dont have to enter it every time.
  7. Restart your SSH connection. Now that localhost:5901 is connected to the port your VNC server is listening on, you can start your VNC viewer and enter localhost:1 as the address of the server. (remember host 1 makes the viewer try to connect on 5901)

  8. It works!

Another thing to remember is that your vnc server keeps running even if you close your ssh connection. You must explicitly kill it. To do this ssh to the machine you started it on and type vncserver -kill :6 (replace the 6 with the actual number of your host).

You can also man vncserver to find all kinds of other options you can do such as set the desktop size.