Configure Vncserver In Linux To Access Remote Desktop Gnome

January 12, 2013 | By in HOWTOS, LINUX HOWTO
| Reply More

VNC stands for Virtual Network Computing. The VNC server allows you to view and access a computer desktop remotely over the network. In Linux, the VNC server is used to display an X session on some other system. This article teaches how you can run VNC server on a Linux machine. For the demonstration purpose of this article, RHEL 5.6 is used.

Installing vncserver package

The package that contains the vnc server is "vnc-server". You need to install vnc-server package if it is not already installed. You can query the package with rpm command. Run the following command to check whether vnc-server is installed or not:

$ rpm -q vnc-server
package vnc-server is not installed

This output shows that vnc-server is not installed. If it is already installed, output similar to following will be displayed on the screen:

$ rpm -q vnc-server

The command "yum install vnc-server" will install the required package for you.

Configuring VNC server

Now you need to create entries for the users you want to allow access to the vnc server. For the purpose, we need to make changes in the configuration file of vnc-server. We will edit /etc/sysconfig/vncservers file:

This file looks like this:

# The VNCSERVERS variable is a list of display:user pairs.
# Uncomment the lines below to start a VNC server on display :2
# 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="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

All of the entries are commented by default. We are interested in second last line. Uncomment this line by removing the leading #. The users that you want to enable for vncserver are written in this line with following list format:

"1:user1 2:user2 ..."

Here we want to enable "raghu" user. So for our case, this line looks like:


Now start the server with following command.

Running vncserver for the first time

$ service vncserver start
Starting VNC server: 1:raghu xauth: creating new authority file /home/raghu/.Xauthority

New 'redhat-server:1 (raghu)' desktop is redhat-server:1

Creating default startup script /home/raghu/.vnc/xstartup
Starting applications specified in /home/raghu/.vnc/xstartup
Log file is /home/raghu/.vnc/redhat-server:1.log

[ OK ]

The Red Hat's default firewall rules block the vnc-server requests. Change the firewall rules by navigating to "System -> Administration -> Security Level and Firewall" in the gnome desktop environment.


In the "Other ports", add port number 5901 with tcp protocol (vnc server uses 5901 port). Save the settings and exit.

Now you can access the server from the client. The gtkvncviewer client is used on the client machine. Enter the server address, username and password in the client


The default desktop accessed from vnc client is very basic


If the whole desktop environment is to be loaded, make changes in the setting file of vnc server in that user's home directory. The file in which changes are to be made is "/home/raghu/.vnc/xstartup" that looks like:

# 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 &

All we need to do is uncomment the top 2 lines to look like:

exec /etc/X11/xinit/xinitrc

Restart the vnc server so that changes may reflect:

$ service vncserver restart
Shutting down VNC server: 1:raghu [ OK ]
Starting VNC server: 1:raghu
New 'redhat-server:1 (raghu)' desktop is redhat-server:1

Starting applications specified in /home/raghu/.vnc/xstartup
Log file is /home/raghu/.vnc/redhat-server:1.log

[ OK ]

This will load the session like this




Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.