I want to use VNC for remote access to a local Centos 6.4 desktop. I've installed tigervnc server, set a password for the user, opened port 5901 in the firewall, and started the vnc server. I tried to connect from another desktop, but get the message:

connection to host was closed

When I try from the commandline, I get this:

vncviewer: ConnectToTcpAddr: connect: No route to host

Searching for an answer, I found that I should change the server settings to allow users to view desktop. I can't find a GUI tool to change this, and am not sure if this is the problem.

How can I get this working?


Below the code from ~/.vnc/xstartup (from the user)


[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
OS=`uname -s`
if [ $OS = 'Linux' ]; then
  case "$WINDOWMANAGER" in
      if [ -e /etc/SuSE-release ]; then
        export PATH
if [ -x /etc/X11/xinit/xinitrc ]; then
  exec /etc/X11/xinit/xinitrc
if [ -f /etc/X11/xinit/xinitrc ]; then
  exec sh /etc/X11/xinit/xinitrc
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
  • 1
    You should check whether this is a problem on the network layer or on the application layer. If the latter is the case then you should adapt the title of your question as it would be misleading then. You can check with telnet 5901. Do you get a connection (which gets closed by the other side) or not even that? Apr 3, 2014 at 16:28
  • I get this: Connected to, Escape character is '^]'. and RFB 003.008
    – SPRBRN
    Apr 4, 2014 at 7:55
  • That means it's not a networking problem but a VNC configuration problem. Apr 4, 2014 at 8:00

1 Answer 1


As a root user, perform the below steps.

vim /etc/sysconfig/vncservers

Add the below 2 lines (where vncuser will be your username).

VNCSERVERARGS[1]="-geometry 1600x1200"

Then type the below commands.

service vncserver start
service vncserver stop
chkconfig vncserver on

If the above commands are successful, we need to edit the xstartup file for whom we have configured the vncserver. So, in our case, we have configured it for the user vncuser.

su vncuser
vi ~/.vnc/xstartup

Uncomment the below 2 lines.

exec /etc/X11/xinit/xinitrc

If the above step is also successful, we are finished with the configuration of the VNC server. If you need more information, I had written a documentation on setting up the VNC server here.

  • I added the contents of .vnc/xstartup to my question. I uncommented both lines, although there are two with xinitrc in it. It didn't help - still no connection.
    – SPRBRN
    Apr 4, 2014 at 8:08
  • Using another VNC viewer, it suddenly worked. The default Ubuntu viewer doesn't work. SSL/SSH VNC Viewer and GTK VNC Viewer both work.
    – SPRBRN
    May 5, 2014 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .