Thursday, October 16, 2008

Setup VNC server for multiuser in Ubuntu 8.4 server

Umakanta Samantaray
usamantaray@gmail.com
D. 17th OCT 2008
Hyderbad, India


Amusing xinit and any/all of the GUI (kubuntu-desktop, KDE, ubuntu-desktop, xubuntu-desktop)already installed.

Now start the process
**********************************

# apt-get install vnc4server
# apt-get install vncviewer
# mkdir -p /etc/sysconfig


*********************************

Create a file by vi editor in /etc/sysconfig/vncservers and put the contains as bleow
*************************************

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

VNCSERVERS="1:user1 2:user2 3:user3 4:user4"
VNCSERVERARGS[1]="-geometry 1280x992 -depth 16"
VNCSERVERARGS[2]="-geometry 1280x1024"
VNCSERVERARGS[4]="-geometry 1280x1024"
VNCSERVERARGS[5]="-geometry 1280x1024"
VNCSERVERARGS[6]="-geometry 1280x1024"
VNCSERVERARGS[7]="-geometry 1280x1024"
VNCSERVERARGS[20]="-geometry 1024x720"
~


******************************************
change the user names to whom you want to give vnc server access. User name should a login acount to that linux box.

Create a script which will run at start up
in /etc/init.d/ named "vncserver" and put below contains in that.
*****************************

#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops vncserver. \
# used to provide remote X administration services.

# Source function library.
# . /etc/init.d/functions

# Source networking configuration.
# . /etc/sysconfig/network

# Check that networking is up.
# [ ${NETWORKING} = "no" ] && exit 0

unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/sysconfig/vncservers ] && . /etc/sysconfig/vncservers

prog=$"VNC server"

start() {
REQ_USER=$2
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS}
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
DISP="${display%%:*}"
export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
fi
done
}

stop() {
REQ_USER=$2
echo -n $"Shutting down $prog: "
for display in ${VNCSERVERS}
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
export USER="${display##*:}"
su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
fi
done
"\n"
echo "Vncserver Stopped"
}

# See how we were called.
case "$1" in
start)
start $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
fi
;;
status)
status Xvnc
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac


****************************************


Cange the script permission
****************************

# chmod a+x /etc/init.d/vncserver

********************************


Now register the service to different runlevels
**********************************

# updat-rc.d vncserver default
# /etc/init.d/vncserver start

# /etc/init.d/vncserver stop

*************************************


Now edit below files in each home direcotory(who need to access vnc server).
Example for user1
**************************************

# vi /home/user1/.vnc/xstartup

*****************************************


Modify as below
********************************************

#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# x-window-manager &
startkde &

*******************************

The above will start KDE in vnc session, for gnome you have to put
********************************************

gnome-session &

*****************************************
in place of startkde &

now ask the users to set the vnc passwod in ssh/telnet terminals in their own login as below
****************************************

$ vncpasswd

***********************************

It will prompt for password two times, porvide it.
*****************************************************

# /etc/init.d/vncserver start

*******************************************

or else
you can reboot to check it automatically start the vnc server for all the users specified in /etc/sysconfig/vncservers

To kill for a perticular user's vnc in his/her login, example for user1 with vnc port no :1
******************************************

$ vncserver -kill :1
to start
$ vncserver :1 -geometry 1024x740

***********************************************

You can also install chkconfig command to on the service start in particular runlevels. download form below link and install as below
*******************************************

http://packages.ubuntu.com/intrepid/all/chkconfig/download
# dpkg --install chkconfig...

*************************************************

You can get other ubuntu help and packages from below links
*****************************************************

http://ubuntuforums.org
http://packages.ubuntu.com

********************************************************
VNC server is ready and users can access it form their desktops by a vnc client.

All query and questions are welcome.
Mail me on usamantaray@gmail.com

No comments: