If you want a moredynamic configuration and the ability to connect for multiple users then there isa better way to do this. As root create the file (and directory if it doesn'texist) /etc/sysconfig/vncservers i.e. do:
mkdir -p /etc/vncserver
touch /etc/vncserver/vncservers.conf
Add servers asneeded for each user by adding something like the following to thevncservers.conf file you just created:
VNCSERVERS="1:justin 2:bob"
VNCSERVERARGS[1]="-geometry 1920x1080-depth 24"
VNCSERVERARGS[2]="-geometry 800x600-depth 8"
next create anempty init script and make it executable:
touch /etc/init.d/vncserver
chmod +x /etc/init.d/vncserver
add the followingto /etc/init.d/vncserver:
#!/bin/bash
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncserver/vncservers.conf ]&& . /etc/vncserver/vncservers.conf
prog=$"VNC server"
start() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS}
do
exportUSER="${display##*:}"
if test -z "${REQ_USER}"-o "${REQ_USER}" == ${USER} ; then
echo -n"${display} "
unset BASH_ENV ENV
DISP="${display%%:*}"
exportVNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
su ${USER} -c"cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP}${VNCUSERARGS}"
fi
done
}
stop() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $"Shutting down VNCServer: "
for display in ${VNCSERVERS}
do
exportUSER="${display##*:}"
if test -z"${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo -n"${display} "
unset BASH_ENV ENV
exportUSER="${display##*:}"
su ${USER} -c"vncserver -kill :${display%%:*}" >/dev/null 2>&1
fi
done
echo -e "\n"
echo "VNCServer Stopped"
}
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
As Stephen mentionedin his answer you'll need to run vncserver AT LEAST ONCE AS EACH USER you wantto login as. I put that in caps because if you skip that step none of it willwork. So as root you could do:
su justin -c vncserver
su bob -c vncserver
This will create a.vnc directory in each users home dir with the appropriate startup scripts.
Finally, do thefollowing:
update-rc.d vncserver defaults 99
now you can eitherreboot or start the service manually by typing:
service vncserver start
Postedby chantra
Linuxservices can be started, stopped and reloaded with the use of scripts stockedin /etc/init.d/.
Thistutorial will explain how one can activate, deactivate or modify a servicestart up.
Wheninstalling a new service under debian, the default is to enable it. So forinstance, if you just installed apache2 package,after you installed it, apache service will be started and so will it be uponthe next reboots.
Youcould either disable this service on boot up by removing any symbolic links in /etc/rcX.d/SYYapache2 or by using update-rc.d.
Theadvantage of using update-rc.d is that itwill take care of removing/adding any required links to /etc/init.d automatically.
Taking apache2 as an example, let's examine how /etc/rcX.d is lookinglike:
Asyou can see, for runlevels 0, 1 and 6 there is a K at the beginning of the link, for runlevels 2, 3, 4and 5, there is a S. Those two letters stands for Kill and Start.
On Debian and Ubuntu, runlevels 2, 3, 4 and 5 are multi-users runlevels.
Runlevel 0 is Halt.
Runlevel 1 is single user mode
Runlevel 6 is reboot
Ifyou want to totally disable apache2 service by hand, you would need to deleteevery single link in /etc/rcX.d/. Using update-rc.d it is as simple as:
Theuse of -f is to force the removal of the symlinks even if thereis still /etc/init.d/apache2.
Note: Thiscommand will only disable the service until next time the service is upgraded.If you want to make sure the service won't be re-enabled upon upgrade, youshould also type the following:
# update-rc.d apache2 stop 80 0 1 2 3 45 6 .
Now,if you want to re-add this service to be started on boot up, you can simplyuse:
Version1.0
Last edited 11/Jun/2014
· RemoteGUI administration makes work easy & convenient.
· Clipboardsharing between host Ubuntu server & VNC-client machine.
· GUItools can be installed on the host Ubuntu server to make the administrationmore powerful
· HostUbuntu server can be administered through any OS having the VNC-clientinstalled.
· Morereliable and faster then running a X-Server over SSH.
· Morereliable then RDP connections.
Iam logged in my system as root user onthe shell (e.g. by ssh). Now I will install the VNC-server.
Pleaseuninstall if tightvnc or anything similar installed.
Inmy case I am using user=srijan it will differ in your case. Youcan use any username for the same.
Itwill show this on the prompt:
srijan@server1:~$ vncserver
You will require a password to access your desktops.
Password:<--Put your VNC password
Verify:<--Put your VNC password
Password too long - only the first 8 characters will be used
xauth: file /home/srijan/.Xauthority does not exist
New 'server1:1 (srijan)' desktop is server1:1
Creating default startup script /home/srijan/.vnc/xstartup
Starting applications specified in /home/srijan/.vnc/xstartup
Log file is /home/srijan/.vnc/server1:1.log
srijan@server1:~$
NowI am going to make backup of the original file & then make the configurationas follows:
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
Itwill have some issues with the gnome-vnc session so please kill the present vncsession as follows:
FurtherI will make the startup script for the vncserver like this:
#!/bin/bash
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$"VNC server"
start() {
. /lib/lsb/init-functions
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() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $"Shutting down VNCServer: "
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
echo -e "\n"
echo "VNCServer Stopped"
}
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
NextI will make the configuration file for the vncserver by creating file asfollows:
NowI will add it into boot startups:
root@server1:~# update-rc.d vncserver defaults 99
Adding system startup for /etc/init.d/vncserver ...
/etc/rc0.d/K99vncserver -> ../init.d/vncserver
/etc/rc1.d/K99vncserver -> ../init.d/vncserver
/etc/rc6.d/K99vncserver -> ../init.d/vncserver
/etc/rc2.d/S99vncserver -> ../init.d/vncserver
/etc/rc3.d/S99vncserver -> ../init.d/vncserver
/etc/rc4.d/S99vncserver -> ../init.d/vncserver
/etc/rc5.d/S99vncserver -> ../init.d/vncserver
root@server1:~#
AndfFinally reboot the machine.
Installvnc server/remote desktop on ubuntu server and enable start at boot
Openthe .vnc/xstartup file for editing.
vim ~/.vnc/xstartup
The file will look like:
#!/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” &
twm &
Type :wq and hit enter. Uncomment the lines that start with unset andexec. Comment out the lines that start with xsetroot, vncconfig, xterm, andtwm.
The final file should look like:
#!/bin/sh
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” &
#twm &
OR
#!/bin/sh
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 &
x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOPDesktop” &
x-window-manager &
Change the permissions on the /etc/X11/xinit/xinitrc file to make itexecutable. Run the server, install Ubuntu Desktop.
chmod 755 /etc/X11/xinit/xinitrc
vnc4server
apt-get install ubuntu-desktop
Remember the number after the colon (:). Log into your remote desktop tocheck the configuration.
vncviewer IP.IP.IP.IP:1
Provide the password that you chose.
Nowif you run vnc4server you can login at port 5901, but it wont start at boot.
Step3: get it to start at boot
Createfile /etc/init.d/vncserver
###BEGIN INIT INFO
# Provides: startVNC
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start VNC server at boot time
# Description: A sophisticated script to do the job.
### END INIT INFO
#!/bin/sh
echo “JOB RUN AT $(date)”
echo “============================”
echo “”
./lib/lsb/init-functions
su my_user -c “/usr/bin/vncserver -geometry 1280×1024 -depth 16″
sudochmod +x /etc/init.d/vncserver
sudo update-rc.d vncserver defaults