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).

 

33 thoughts on “How To: Configure VNC Server

  1. Although, i didn’t go thru the whole thing and i don’t know what gray scale is but vnc just works! i mean, ur configuration regime seems overkill to me or is there something different to this from the normal simple way ?
    at least, the desktop screenshots tell me its the same thing.

  2. hey i have been using vncserver to connect to my gnome desktop in fedora 8.
    but theres a problem . i dont get the panels , close , minimize buttons etc on windows and wiondows is not movable, it just sticks to the top left corner of screen.

    if u can then please help.
    waiitng for ur reply thnaks !!

  3. @Dan

    Windows vncviewer works great irrespective of the situation whether a user is loggen in or not. There may be some problem with your configuration files. Paste you configuration files somewhere n I’ll see if I can help.

  4. using vncviewer to connect on a remote desktop with KDE, is working, but what i see is not the current desktop on the remote machine, is a new KDE desktop. i can’t see what aplications are running on the remote machine.
    that is working with vnc server on windows machines.

  5. i’m using vncviewer on local machine, and conf files on remote machine are
    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
    # .

    # 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:romeo”
    VNCSERVERARGS[1]=”-geometry 1024×768″

    ——————————————————————————————————
    and:
    ——————————————————————————————————

    #!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
    startkde &

    ——————————————————————————————————
    for example, on local machine i’m logged with kopete on my yahoo messenger
    acount, and every time i launch on local machine

    vncviewer IP:1

    i’l be logged out from kopete because kopete is launching on remote machine

  6. i’m using vncviewer on local machine, and conf files on remote machine are
    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
    # .

    # 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:romeo”
    VNCSERVERARGS[1]=”-geometry 1024×768″

    ——————————————————————————————————
    and:
    ——————————————————————————————————

    #!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
    startkde &

    ——————————————————————————————————
    on local machine:

    vncviewer :1

    and i don’t see aplications running on remote machine

  7. hi Mr.Saini

    i’m using ubuntu..how to configuration in ubuntu???

    because i read, you wrote :
    “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.”

    what are the minor modifications???

  8. Did you try with the given configurations? I wrote minor modifications because I am not sure if it works. Can you please try with the configurations given here?

  9. VNC Server is only capable of providing access to session zero. If a different user session is the active console session whena VNC viewer connects, VNC Server will attempt to make session zero the console session.
    alarm systems

  10. I’m trying to get the VNC server running on an FC3 distribution. I’ve followed your instructions and everytime I try to start Xvnc with vncserver, I get a ‘failed’ message. (i’m doing this from CLI.)
    What should might be preventing it from starting up?

  11. Try this on command line
    [root@localhost root]# Xvnc :1 [Enter]

    if this also fails, try 2,3,4 or any other higher integer instead of 1. If you still get the error, then paste the exact error you are getting.

  12. Trying this for 4 days now, no success….the files you mention to edit under sysconfig are not editable at all.
    It’s totally beyond me why a task that lasts 2 minutes on a win XP machine like installing VNC server and letting it run properly, takes 4 days on a linux machine.
    Why do we have to configure so many things, with close to no help, no documentation and no logic behind it?
    Fedora is as unusable as ever… Even with this guide … Even the very first steps of this guide asume you can edit all these files… well I can’t.

  13. Do you have sufficient permissions to edit those files? To edit anything in /etc/sysconfig you need to be root.

  14. The persistent desktop due to VNC is really useful. Highly recommended to everyone.

    I use VNC with IceWM.

  15. This is a useful article.
    How about updating it for Fedora 11/12?
    Most of it could stay the same, but the yum package might be tigervnc-server.
    No doubt there would be a few other tweaks uncovered by trying it …

  16. These instructions appeared to work on Fedora 12 until till I tried to connect. Then all I get is a black screen at the dimensions I specify. It’s not my local client since I have tried three different ones from two different machines.

    Is it the firewall? The Fedora 12 box is running headless so it is not “logged in”. I’m trying for a solution which will work in that state. Actually I’m using the box with the Amahi server package. Very cool. Anyway, I would appreciate any VNC help with my Fedora 12 box. Thank you.

  17. For recent Fedora distributions, don’t forget you have to

    yum install tigervnc-server

    Otherwise, you just get the viewer

  18. Doesn’t work at all on FC13. Nothing but blank screens or black screens.

    I’ve configured this easily many times on older FC6-8 machines no problem.

  19. It worked great for me. Thanks for posting the instructions. I can’t seem to get the display greater than 800×600 though, but now I can access the machine remotely and with a usable display.

  20. Pingback: Using vnc in RHEL
  21. There’s no vncservers in /etc/sysconfig even though I did yum -y install vnc and yum groupinstall “GNOME Desktop Environment”.

    [root@server sysconfig]# ls -a
    . i18n named readonly-root snmptrapd
    .. init netconsole rsyslog sshd
    cbq ip6tables-config network samba wpa_supplicant
    console iptables-config networking saslauthd xinetd
    crond man-db network-scripts sendmail
    httpd modules rdisc snmpd

Comments are closed.