Friday, August 27, 2010

Configuring VNC server on Linux hosts

Linux shell is a powerful and necessary tool for Linux administrator. You can do everything from command line, but, in some cases, there is useful a GUI for some tasks. In this post I will setup VNC server on two Linux boxes : Centos 5.5 and Ubuntu 10.04 desktop version. VNC allows admins to interact with a graphical interface in Linux hosts. This is similar to "Remote Desktop Connections" in Windows Servers.

Installing VNC on a Centos box

In some linux distributions VNC server is installed by default , if don't, use yum to install it
# yum install vnc vnc-server

Now you must specify a password for connecting to desktops.
# vncpasswd
Password:
Verify:
It creates a pass for user root. Remember security password considerations.

To start a session, only type
# vncserver :1
It will create a desktop session numbered as "one". This number is important. It defines the port used to establish connections with VNC server. The ports will be discussed later.

To connect to VNC server used a VNC client and specify connection parameters.


 
After IP address, type :<number of desktop>, the same you used previously, and click connect. Specify the password that you set and you will get this.

With this terminal you can configure system settings in graphical mode, e.g. system-config-users

Now if you want to access a full gnome terminal you should change the following:

Edit /root/.vnc/xstartup
[root@localhost ~]# vim /root/.vnc/xstartup
#!/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 &

--> Note the changes :

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

The two commented lines were uncommented and the last line was changed to "startx" to start gnome sessions. This changes only affect new VNC sessions. You don’t have to restart any service.

Now we have a beautiful and fully gnome session:


 
If you want to stop VNC server you can do;
 #service vncserver stop
or for a particular session
#vncserver -kill :<number of session>

Also if you want to use a web browser point it to

Installing VNC on an Ubuntu 10.04 box

Install vnc4server.
#apt-get install vnc4server  vnc-java
Set a password:
#vnc4passwd

The config files are located in the same place /home/user/.vnc or /root/.vnc. Edit de xstartup file in the same way. After that, you should give the file /etc/X11/xinit/xinitrc execution permissions.

# chmod 755 /etc/X11/xinit/xinitrc

Use the client and that's all.
 


"The m and s syndrome"

If you did the above steps for Ubuntu 10.4 almost all work is finished . But, when you connect to VNC server  and you type letter "m" or "s" the indicator applet shows you mail menu and session menu respectively. You may remove this icons from your desktop but I didn't like that. This behavior is a bug in indicator applet version 0.3.6 for Lucid. In the 0.3.7 the bug is fixed it.

To compile it, first install :
intltool
libgtk2.0-dev
libappindicator-dev
libpanel-applet2-dev

Compiling:
#./configure
#make
#make install

By default binaries are installed in /usr/local/libexec, but they must be placed in /usr/lib/indicator-applet/
Close all X sessions and do:
cp /usr/local/libexec/* /usr/lib/indicator-applet/
Now you can start your session without the "m and s syndrome" .

 


Required ports  to establish VNC connections

VNC uses the following mechanism for assigning ports. The port used for a session is the sum of 5900+<number of the session that you select>. For example if you select session number 3 (vnc4server :3), the port used for it is 5900+3=5903. In the same way for web access but beginning in port 5800. In your firewall you should open a range of ports to allow VNC connections. 

Using a SSH tunnel to encrypt data transmission

VNC is unsecure in nature. If you need to establish a connection over an unsecured network you may desire to protect it using SSH encryption mechanisms.  We will use putty for that.

Configure putty tunnel  in this way:


 
Then, point your vnc client to localhost:3000 (in this case)


And that's all!!!.


No comments:

Post a Comment