Tuesday 29 April 2014

Setting up a VNC Server on a CentOS 6.5 NeCTAR instance

How to get a GUI interface to a virtual machine. These instructions are written for the NeCTAR Centos 6.5 image.


Step-by-step guide

These instructions assume that you have already got a NeCTAR VM instance (based on the NeCTAR Centos 6.5 image) up and running and have ssh access to the VM.
  1. ssh into your instance:
    $ ssh ec2-user@130.xxx.xxx.xxx
    • substitute in the IP address of your nectar instance. You can find this on the NeCTAR dashboard.
  2. Install the required packages:
    $ sudo yum groupinstall Desktop 
    • installs the packages required to setup a minimal desktop that can be used as a thin client
    • type yum groupinfo Desktop to see what packages will be installed when you run this
    $ sudo yum install tigervnc-server
    • install the vnc server
    $ sudo yum install xorg-x11-fonts-Type1
    • optional - installs some additional fonts
    $ sudo yum install vnc 
    • installs the vnc client
  3. Edit /etc/sysconfig/vncservers and add the following to the end of the file:
    VNCSERVERS="1:ec2-user"
    VNCSERVERARGS[1]="-geometry 1024x600 -nolisten tcp -localhost""
    This assumes you are going to vnc into the ec2-user account - if using an account other then ec2-user then substitute username accordingly.

    It also sets up the vncserver so that it can only be connected to via an ssh tunnel - this is a security measure. To remove this just leave off the -nolisten tcp -localhostfrom the VNCSERVERARGS[1].
    The number used in the VNCSERVERS statement is significant - it indicate what port to connect to. VNC use port 5900 + the number. So in this case, the vnc server for the ec2-user will be available on port 5901.

  4. Make a vnc password for the user. Login to the user and run the following command:
    $ vncpasswd
    Password:
    Verify:
  5. If you want to start your vnc server automatically on every reboot, run the following:
    $ sudo chkconfig vncserver on
    If you just want to start the vncserver manually use
    $ sudo service vncserver start
  6. To check that the vncserver is running
    $ service vncserver status
    Xvnc (pid 17709 17663) is running...
  7. If you have configured the VNCSERVERARGS as per instructions in step #3 you will need to set up an ssh tunnel on your desktop machine to connect to the server. If you are using a Linux or Mac OSX system, open a terminal window and use the following command:
    ssh -L 15901:localhost:5901 -N -f -l ec2-user 130.xxx.xxx.xxx

    If you are on a Windows machine, you will need to use PuTTY to set up the ssh tunnel. See http://nodivisions.com/tech/vnc/ for instructions on how to do this.
  8. Now start a VNC viewer on your local machine and connect to localhost using port 15901 (127.0.0.1:15901). You will be prompted for the vnc password that you created in step #4. If you don't have a vnc viewer, a google search should reveal numerous free options.

    If you are on a Mac, you can use the "Connect to Server" functionality in Finder:
  9. This will open Screen Sharing and prompt for the vnc password. If you don't get prompted for the password then there is some problem with the ssh tunnel. To debug this, add the flags -vvv to the ssh command in step #7 to try and diagnose what is going wrong.

References

  1. el Khamlichi, M. (2013, August 22). Install VNC Server on CentOS 6.4. Retrieved April 24, 2014 from http://www.unixmen.com/install-vnc
  2. Shine Servers (2013, November 24). How to Install VNC Server On CentOS. Retrieved April 24, 2014 from http://blog.shineservers.com/install-vnc-server-centos/
  3. Nix Craft (2006, May 8). HowTo: Tunneling VNC Connections Over SSH. Retrieved April 24, 2014 from http://www.cyberciti.biz/tips/tunneling-vnc-connections-over-ssh-howto.html
  4. Prashar, Vinay (2008, September 25). How Connect to a VNC Server in MAC OSX Leopard. Retrieved April 24, 2014 from http://ihackintosh.blogspot.com.au/2008/09/how-connect-to-vnc-server-in-mac-osx.html
  5. Bartlett, Alan (2012, November 07). VNC (Virtual Network Computing). Retrieved April 24, 2014 from http://wiki.centos.org/HowTos/VNC-Server
  6. DiSante, Anthony (2014). Controlling a Computer Remotely with VNC. Retrieved April 29, 2014 from http://nodivisions.com/tech/vnc/

No comments: