VNC Server under Linux

Charles Roth, 9/4/2009       (TechBlog top)

I. Introduction & Purpose
There have been many occasions where I wanted to install software on a remote linux server, but had to do some complicated navigation thru web pages to actually get to and download the software.

It's a pain to download the software to my laptop, and then re-upload it to the server -- and frequently slow, to boot, as the server usually has a lot more bandwidth than my laptop connection (think Panera, Barnes & Noble, etc...)

II. Solution.  VNC Server
So the solution is to use a VNC client on my laptop to connect to a virtual desktop on the server, which in turn is running the VNC server.  The results can be (visually speaking) somewhat ugly, but it works!

III. Installation details for RHEL 5 or CentOS 5
As root, do:

  1. yum install vnc.i386
  2. yum install vnc-server.i386
  3. yum install gnome-session.i386
  4. yum install gnome-utils.i386   (this step may be optional)
  5. yum install gnome-terminal.i386
  6. yum install firefox.i386   (presumably you want a browser...)
  7. vncserver    (this starts the vncserver, but clumsily.  It will ask for a password, which will be used when you want to connect from a VNC client.)
  8. vncserver -kill :1    (kills the server)
  9. Edit the file .vnc/xstartup.  Uncomment the two lines it suggests uncommenting(!!).  The last line should be (or be replaced by) "exec gnome-session &".
  10. Change your firewall to allow incoming access on port 5901, ideally for just a limited set of IP addresses.
  11. vncserver    (restarts the vncserver with all of the proper options)

IV. Installation details for RHEL 6 or CentOS 6
As root, do:

  1. yum install gtk-vnc.i686
  2. yum install tigervnc-server.i686
  3. yum install gnome-session.i686   (this step may be optional)
  4. yum install gnome-utils.i686   (this step may be optional)
  5. yum install firefox.i386   (presumably you want a browser...)
  6. vncserver    (this starts the vncserver, but clumsily.  It will ask for a password, which will be used when you want to connect from a VNC client.)
  7. vncserver -kill :1    (kills the server)
  8. Edit the file .vnc/xstartup.  Uncomment the two lines it suggests uncommenting(!!).  The last line should be (or be replaced by) "exec gnome-session &".
  9. Change your firewall to allow incoming access on port 5901, ideally for just a limited set of IP addresses.
  10. vncserver    (restarts the vncserver with all of the proper options)

V. Usage Notes
Normally I wouldn't just leave the vncserver running on the server.  So I just turn it on when I need it, then kill it.

  1. ssh/putty to the server, and just type "vncserver".  That will start up the VNC server.
  2. Use a vnc client in the normal way to connect, except that the host will be (say) myhost.com:1.
  3. Once you're in, you'll see a web browser button on the menu bar at the top.  That's probably the only reason you'll want to be using vncserver in the first place.  Other tools (e.g. terminal/shell window) are available from the menus.
  4. When you're done, make sure to do a "vncserver -kill :1" to kill the server.
  5. Unlike Windows, it's actually possible to have many vncservers running on the same physical server (i.e. on ports 5901, 5902, etc).  Right now I can't think of any practical uses for that, but it's there.  Also unlike windows, there's no "main desktop session" to connect to, since presumably the server is running "headless" -- no monitor!

Enjoy!  I hope this helps.  Feedback or other information is welcome at roth@thedance.net.