How To: Configure VNC Server

Vncserver is just another application available in almost all the available Linux based distros. Configuring vncserver is very easy. But the default desktop view in vncviewer is gray scale desktop with very pathetic GUI. To view normal Gnome or KDE desktop in vncviewer, assigning a custom port for usage, user configuration and to adjust the resolution of the vncviewer window, some files need to be configured properly. Here are the required configuration in any version of Fedora/Fedora Core. But with minor modifications these can be applied to other distros like Ubuntu, SuSE, Gentoo etc.

Step 1: Installing Vncviewer, Vncserver

As root do this

[root@bordeaux saini]# yum install vnc [Enter]

Step 2: Configuring resolution, port & user

The default location of server configuration file for vncserver is ‘/etc/sysconfig/’. To configure the resolution, user and port open ‘/etc/sysconfig/vncservers’ in you favorite editor and add two lines per user configuration shown ..

VNCSERVERS=":"
VNCSERVERARGS[]="-geometry x x"

Example :

VNCSERVERS="3:saini"
VNCSERVERARGS[3]="-geometry 1000x700"

You can choose any display port, but it should not be in use by another X server. Window height and width can be anything (not in fraction of course). But keep in mind that the system on which you are going to view the desktop using vncviewer should have greater resolution than what you specify here, otherwise scrollbars will appear.

Step 3: Configuring Desktop Environment

The user specific configuration files of vncviewer resides in ‘.vnc’ directory in user’s home directory. (e.g. ‘/home/saini/.vnc/’). Open ‘.vnc/xstartup’ in your favorite editor and edit as below

  • For Gnome

The ‘xstartup’ file shout look like this

#!/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 &
startx &
  • For KDE

The ‘xstartup’ file should look like this

#!/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 &
startkde &

Step 4: Configuring password

For setting up vncviewer password for user ‘xyz’, login as user ‘xyz’ and issue ‘vncpasswd’ command on a terminal/konsole (or whatever). Enter password twice and you are done with password setting.

Step 5: Starting Vncserver

To start vncserver, login as root and issue ‘service vncserver start’ command. If service started successfully, you are ready to use vncviewer on a remote/local machine.

Step 6: Accessing through Vncviewer

  • From Linux based machines
[saini@bordeaux saini]# vncviewer IP_Address:displayPort [Enter] #(IP Address is for the machine where you set up vncserver)
  • From Windows

On windows there is a software called RealVnc. Install it and enter <IPAddress>:<displayPort> in the dialog box.
[I explained how to connect via windows because it may help someone get a bit of relief.]

Screenshots:

  • Vncviewer with Gnome as Desktop environment

VNC Server VNC Viewer Screenshot GNOME

  • Vncviewer with KDE as Desktop environment

VNC Server VNC Viewer Screenshot KDE

Vnc is nice tool if you want to avoid using windows. I use it all the time. While I am forced to work on windows system, I install vncviewer and use it in full screen mode 😛 It also helps when you want to run some gui based application and monitor is remotely. Because if you close vncviewer window and use vncviewer again, you will be given the desktop session where you left it (all windows open and applications running).