Connecting to a Linux server using VNC

Many of my computers are not in my office/den but are providing server functions for which the need to access them directly is rare. When I do need access to the Windows machines, I can connect to them using a variety of RDP clients; for my Red Hat Enterprise Linux (RHEL) 5 box it’s a similar situation but this time using SSH (for command line access) or VNC (for a GUI).

Although RHEL includes a VNC server and I’d opened up TCP port 5900 in the firewall configuration (using system-config-securitylevel), for some reason I was still having problems creating a VNC connection and it turns out that there were two main reasons for this.

  1. Each VNC display will use a new port number, so display 0 is on 5900, display 1 on 5901, etc. I was trying to connect on port 5900 but it’s not as simple as opening the port – I needed to start a session with vncserver (supplying a password if required – the vncpasswd command can also be used for this), then note the port number (open the appropriate firewall ports) and connect from my chosen VNC client.
  2. For connection to an existing logged on console session on the server running a graphical environment (display 0), it’s necessary to enable this in the Remote Desktop preferences:

Remote Desktop PreferencesOnce I’d got around this, it was fairly straightforward to connect to display 1 on port 5901 but the default display was using the rather dated Tab Window Manager(TWM) GUI (although starting GNOME applications like gedit applied the GNOME look and feel to that application’s window. By editing the /root/.vnc/xstartup file I could comment out the twm & line and replace it with startx &; however, because there was already an instance of X running on the server (for display 0), I found that the startx & command failed and I needed to use gnome-session & in its place. I also commented out the line starting with xterm and included gnome-terminal & at the end of the script so my xstartup file now reads:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
# xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# twm &
gnome-session &
gnome-terminal &

Just for completeness, here are a few more notes that might be useful:

  • Use chkconfig --list to check whether the VNC server service is started by default (if necessary, use chkconfig --levels 5 vncserver to make it start in run level 5 in future).
  • If not already running, then start the service with service vncserver start.
  • Kill VNC desktops with vncserver -kill :displaynumber.
  • VNC sessions may be tunnelled through SSH for a secure connection.

One thought on “Connecting to a Linux server using VNC


  1. Mark,

    VNC is OK, but if you want better experience, feel, and performance – go with nomachine at http://www.nomachine.com/download.php. download the free edition. There is a GPL version but this is much better – I am not a Linux zealot that cares about the philosophy between GPL and excellent software (some commercial). Remember to have an account on your Red Hat / CentOS or any Linux as a normal user and log into that Linux machine from another machine using the NoMachine client into the NoMachine server – think of it as Citrix client to Citrix server…

    Good luck,

    LL

Leave a Reply