Wednesday, March 11, 2009

Using VNC to connect to X-Windows display


Before VNC, we may use Xming or XWin32 to connect to a proper configured X-Windows Server.  This requires few X-Windows Server setup to get it done.

Since Fedora 7, there is a new service to connect to X Windows Server much easily.  This service is VNCServer.


Using yum to query and install for vnc-server rpm packages:

# yum list vnc-server
Installed Packages
vnc-server.i386                          4.1.2-23.fc8           installed

# yum install vnc-server.i386

VNC Server Configuration

  1. Define VNC server instances in /etc/sysconfig/vncservers:

    VNCSERVERSARGS[1]="-geometry 1024x768 -nohttpd"

  2. Each VNC server instance listens on port 5900 plus the display number on which the server runs. In our case, myuser’s vnc server would listen on port 5901 (5900 + 1).
  3. You may setup multiple vnc instance as well:

    VNCSERVERS="1:myuser 2:user01 3:user02"
    VNCSERVERARGS[1]="-geometry 1024x768 -depth 16"
    VNCSERVERARGS[2]="-geometry 800x600 -depth 8"
    VNCSERVERARGS[3]="-geometry 1024x768 -depth 16"

  4. In this case, the vnc server would listen on port 5901, 5902 and 5903 respectively.
  5. In myuser's account, setup vnc password for the user:

    # vncpasswd
  6. Start VNC Server:

    # service vncserver restart
    # chkconfig vncserver on

  7. Define a new Firewall rule (/etc/sysconfig/iptables):

    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

More User Configuration

Once vncserver has startup for the first time, it will create a default xstartup config file.  You may define your own startup script:

# vi /home/myuser/.vnc/xstartup


# Uncomment the following two lines for normal desktop:
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 &

Connect to VNC Server

You may use any vesion of vncviewer to connect to the VNC Server.  For example, download TightVNC viewer for Windows.  The connection string is something like:


Enter password and you may connect to your X windows service remotely.


  1. Set up the VNC Server in Fedora

No comments: