Setup VNC-Server Ubuntu/Debian OS

This guide is for installing and setting up a VNC-Server on the servers installed with Ubuntu/Debian OS. 

1. Log in to the server as root

 

2. Run the following commands:

apt-get update

apt-get install gnome-core xfce4 firefox

apt-get install vnc4server

You need to make sure that you are using only vnc-server and no other VNC-server installations were present in the server as this could give errors in future mostly that clipboard sharing between the host Ubuntu Server and vnc-client machine. You can check it using the following command:

root@vnctest ~ # dpkg -l | grep vnc

ii  vnc4server                                            4.2.3+xorg4.3.0-37ubuntu5                           amd64        Virtual network computing server software

root@vnctest ~ #

Please uninstall if TightVNC or any other installations there. 

 

3. Once the above packages are fully installed, we need to add a normal user for using VNC

useradd jack

You need to use your own username here.

Then use the following command:

su - jack

vncserver

Put a password for the vnc user there and verify the same.

 

4. We need to copy the original file and create a new configuration file as shown below:

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak

> ~/.vnc/xstartup

vi ~/.vnc/xstartup

 

5. Edit the file as below:

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

 

6. There will be some issues with the gnome-vnc session so we need to kill the present vnc session as below:

# vncserver -kill :1

 

7. Then we need to make a startup script:

su 

vi /etc/init.d/vncserver

and paste the following:

#!/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

Then we need to make it executable:

chmod +x /etc/init.d/vncserver

 

8. We need to create a configuration file for VNC:

mkdir -p /etc/vncserver

vi /etc/vncserver/vncservers.conf

Paste the following:

VNCSERVERS="1:jack"
VNCSERVERARGS[1]="-geometry 1024x768"

 

9. If you need to make it started after the reboot automatically, a startup script needed to be written on the rc.d like below:

update-rc.d vncserver defaults 99

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 

 

10. Reboot the server. 

  • vnc ubuntu, vnc debian
  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

How To Install and Use Docker on Ubuntu 16.04

Introduction Docker is an application that makes it simple and easy to run application processes...

Change Main IP of the server :: Vesta Panel

If we are changing the main IP of a server installed with Vesta panel, we can use the following...

cPanel: Apache-FastCGI Data Timeout Error

If you are using a cPanel server and have FastCGI enabled in Apache, you might be facing the...

Domainkey installer in cPanel

You can use the following cPanel script to install domainkey for an account...

Email issues :: Common Troubleshooting Steps

Here I will discuss some common errors and their solution: We are using a mail relay setup for...