Header Shadow Image


Linux: VNC Connections or the equivalent of Remote Desktop Connection (RDC) in Windows

VNC or the Linux equivalent of Remote Desktop Connection in Windows, allows us to establish a GUI connection to our remote Linux machines as if we were sitting at the machine itself.  Here, we'll undertake the task of configuring this sort of connection to allow us to remotely interact with the Gnome Desktop.

In this case we'll use tigervnc as it's the best available and complete one to date, AFAIK.

# yum search tigervnc

tigervnc.x86_64 : A TigerVNC remote display system
tigervnc-server.x86_64 : A TigerVNC server
tigervnc-server-applet.noarch : Java TigerVNC viewer applet for TigerVNC server
tigervnc-server-module.x86_64 : TigerVNC module to Xorg

# yum install tigervnc.x86_64 tigervnc-server.x86_64 tigervnc-server-applet.noarch tigervnc-server-module.x86_64

Enable it:

# chkconfig|grep -i vnc
vncserver       0:off   1:off   2:off   3:off   4:off   5:off   6:off
#
# chkconfig –list vncserver
vncserver       0:off   1:off   2:off   3:off   4:off   5:off   6:off
#
# chkconfig –level 5 vncserver on
# chkconfig –list vncserver
vncserver       0:off   1:off   2:off   3:off   4:off   5:on    6:off
#
# which vncserver
/usr/bin/vncserver
# rpm -qf /usr/bin/vncserver
tigervnc-server-1.0.90-0.15.20110314svn4359.el6_1.1.x86_64
#

You may get an error restarting / starting it:

# service vncserver restart
Shutting down VNC server:                                  [  OK  ]
Starting VNC server: no displays configured                [FAILED]
#

Let's check what configs we may need to adjust:

# rpm -ql tigervnc-server-1.0.90-0.15.20110314svn4359.el6_1.1.x86_64
/etc/rc.d/init.d/vncserver
/etc/sysconfig/vncservers
/usr/bin/Xvnc
/usr/bin/vncconfig
/usr/bin/vncpasswd
/usr/bin/vncserver
/usr/bin/x0vncserver
/usr/share/man/man1/Xvnc.1.gz
/usr/share/man/man1/vncconfig.1.gz
/usr/share/man/man1/vncpasswd.1.gz
/usr/share/man/man1/vncserver.1.gz
/usr/share/man/man1/x0vncserver.1.gz
#

 

Next we will edit the VNC config file:
 

# cat /etc/sysconfig/vncservers
# 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 this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# 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 800×600 -nolisten tcp -localhost"
[root@mbpc ~]#

 

We'll configure it in this manner however:

VNCSERVERS="1:videouser 2:root"
VNCSERVERARGS[1]="-geometry 1280×1024"
VNCSERVERARGS[2]="-geometry 1280×1024"

NOTE: root user is only for demonstration purposes, remove for final product.  Don't forget to set the password or you will get:

# service vncserver start
Starting VNC server: 1:root
Setting the alias ll ….
                                                           [FAILED]
[root@mbpc ~]# vncpasswd
Password:
Verify:
Password:
Verify:
#

su - to each account and rerun vncpasswd.  The password will be stored in ~/.vnc/passwd:

# su – videouser
[videouser@mbpc ~]$ vncpasswd
Password:
Password must be at least 6 characters – try again
Password:
$

If you get the above error, and you really really must insist on using a short password, try this:

[videouser@mbpc ~]$ cd .vnc
[videouser@mbpc .vnc]$ vncpasswd -f > passwd
(password typed here wont' be seen)
[videouser@mbpc .vnc]$

Then set the password of videouser and (If you are even more brave, root)

# service vncserver restart
Shutting down VNC server:                                  [  OK  ]
Starting VNC server: 1:videouser
New 'mbpc:1 (videouser)' desktop is mbpc:1

Starting applications specified in /home/videouser/.vnc/xstartup
Log file is /home/videouser/.vnc/mbpc:1.log

2:root Setting the alias ll ….

New 'mbpc:2 (root)' desktop is mbpc:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/mbpc:2.log

                                                           [  OK  ]
#

Then check the results:

# netstat -na|grep -i 590|awk '{ if ( $NF ~ /LISTEN/ ) print; }'
tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:5902                0.0.0.0:*                   LISTEN
#
#
# tail /etc/sysconfig/vncservers |grep -v "#"

VNCSERVERS="1:videouser 2:root"
VNCSERVERARGS[1]="-geometry 1280×1024"
VNCSERVERARGS[2]="-geometry 1280×1024"
# ps -ef|grep -i vnc
500       4534     1  0 16:15 ?        00:00:00 /usr/bin/Xvnc :1 -desktop mbpc:1 (videouser) -httpd /usr/share/vnc/classes -auth /home/videouser/.Xauthority -geometry 1280×1024 -rfbwait 30000 -rfbauth /home/videouser/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn
500       4540  4539  0 16:15 ?        00:00:00 vncconfig -iconic
root      4630     1  0 16:15 pts/2    00:00:00 /usr/bin/Xvnc :2 -desktop mbpc:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1280×1024 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn
root      4928  4927  0 16:15 pts/2    00:00:00 vncconfig -iconic
root      5495 28852  0 16:18 pts/2    00:00:00 grep -i vnc
#

Test drive the connections from remote Linux machines in this manner:

# /usr/bin/vncviewer

TigerVNC Viewer for X version 1.0.90 – built Jun 24 2010 09:55:22
Copyright (C) 2002-2005 RealVNC Ltd.
Copyright (C) 2000-2006 TightVNC Group
Copyright (C) 2004-2009 Peter Astrand for Cendio AB
See http://www.tigervnc.org for information on TigerVNC.
/usr/bin/vncviewer: unable to open display ""
#

The error means don't forget to run it from the GUI of that machine, not the remote SSH console.  ;)

 

Let's try this from Windows 7 now. First download TightVNC VIEWER (unless you're interested in the Windows based server as well).  This should come as a JAR file (.jar) that is a Java executable file.  Extract it, if you got the .ZIP and place it where you want it (it's not an installer).  Next run it:

tightvnc-jviewer.jar

And login:

TightVNC Login Connection Screen

Unlike the image though, use the IP and PORT applicable to your case (typically it's 5901, 5902, 5903 etc for each user you are running it for).

Cheers,
TK

 

Leave a Reply

 


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License