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.
- 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
vncpasswdcommand can also be used for this), then note the port number (open the appropriate firewall ports) and connect from my chosen VNC client.
- 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:
Once 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:
# 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 &
Just for completeness, here are a few more notes that might be useful:
chkconfig --listto check whether the VNC server service is started by default (if necessary, use
chkconfig --levels 5 vncserverto 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.