Linux [ServerSupport]

Configuringring VNC Server - Linux

VNC Server Config

Server Side Configuration.

Package Required.

Note:By default the above binaries are installed at the time of OS Installation

To Check what is installed

First check if you already have them installed on your system, open a terminal and type:

$ rpm -qa|grep vnc 
If you get an output something like above then you have it already, if not you need to install it download the binaries or using yum command.

Steps to Configure the VNCServer

  • Step1: Create a user on the vnc server
    [ ]# useradd user1
    [ ]# passwd user1
    Step1 can be skipped in case of using existing users.
  • Step 2:

    Editing vncservers file i.e., vi /etc/sysconfig/vncservers

    # The VNCSERVERS variable is a list of display: user pairs.
    # Uncomment the line below to start a VNC server on display :1
    # as my 'myusername' (adjust this to your own). You will also
    # need to set a VNC password; run 'man vncpasswd' to see how
    # to do that.
    # DO NOT RUN THIS SERVICE if your local area network is
    # untrusted! For a secure way of using VNC, see
    # <URL:>.
    # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.# Use "-nohttpd" to prevent web-based VNC clients connecting.
    # Use "-localhost" to prevent remote VNC clients connecting except when
    # doing so through a secure tunnel. See the "-via" option in the
    # `man vncviewer' manual page.

    VNCSERVERS="1:user1 2:user2"
    VNCSERVERARGS[1]="-geometry 800x600 -depth 16"
    VNCSERVERARGS[2]="-geometry 800x600 -depth 16"

now save file and exit.

  • Step 3:

    login as user1 & use vncpasswd command to give vnc password
    [ user1]$ vncpasswd

  • Step 4:

    [ user1]$ vncserver :1

    Once the above command is executed it creates a file xstartup under users home folder in .vnc folder, in which vnc session will be twm session. To have kde or gnome session we need to replace the twm session line to kde or gnome in xstartup file as shown below.

  • Step 5:

    vi /home/user1/.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 &
    startkde & => KDE Mode
    startx & => GNOME Mode
    gnome-session => GNOME Modee

  • Step 6:
    service vncserver stop/start/restart (can be used to start / stop the service)
  • Note:
    • Killing one user's vnc session
      vncserver -kill :1
    • Activating one user's vnc session
      vncserver :1

Knowing Which PORT to Use.

  • It's also important to note the session number of a user, as this will tell us which port vncserver will listen on. Remember the Gnome Remote Desktop to use "computername:0" as the connection string, the number needs to be added to 5900 to get the listening port. In this case, we need to use port 5901 since we are using session 1. In the same way, we could use any number, for example:
    VNCSERVERARGS[2000]="-geometry 1024x768 -depth 16"
    In this case, we need to use port 5900 + 2000 so port 7900.

Invoking VNC Session Directly at Command Prompt

$ vncserver -geometry 1325x680 -depth 24 -cc 4 -name "$HOSTNAME - `finger $USER | head -n 1 | cut -d ":" -f 3`"


You can use the same command as alias in your basch script, just add the below line in .bashrc file.

export HOSTNAME=`hostname | cut -d "." -f 1 | tr 'a-zA-Z' 'A-Za-z'`
alias vncstart='vncserver -geometry 1325x680 -depth 24 -cc 4 -name "$HOSTNAME - `finger $USER | head -n 1 | cut -d ":" -f 3`"'

Invoking VNC Viewer - Linux/Windows

  1. Open VNC Viewer
  1. To get full color, go to the option select Full (all available colors)
  1. Once you select / set the required options you want, click on OK and OK to connect, where it will ask you to enter the password. One password which you created wile invoking the vnc server on the server.
  1. Now your VNC Session on the linux server is up and ready to use.