Skip to content

How to install VNC Server on Debian 8

Install VNC Server on Debian

Very similar to Ubuntu (since Ubuntu is based on Debian), you only need to use vnc4server package to install VNC Server

# apt-get install tightvncserver

Configure VNC Server to work on Ubuntu 14.04 / Debian 8

You can use any privileged user or root user to login to your VNC Server, but for security reason, I’m going to create vncuser for my VNC Server (you can change vncuser in tutorial to any user that you would like to use, it can be your existing user)

# adduser vncuser
# passwd vncuser

We now switch to vncuser to create some VNC configuration’s files.

# su - vncuser

With regular or privileged user, start vncserver for vncserver to creates it’s necessary files.

$ vncserver

After you started VNC Server, you will be asked to create VNC’s password (VNC password can be different or the same password as your user’s password)

vncuser@namhuy:~$ vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth:  file /home/vncuser/.Xauthority does not exist
 
New 'namhuy:1 (vncuser)' desktop is namhuy:1
 
Creating default startup script /home/vncuser/.vnc/xstartup
Starting applications specified in /home/vncuser/.vnc/xstartup
Log file is /home/vncuser/.vnc/namhuy:1.log

After VNC Server generated files, we have to kill it in order to configure xstartup file.

$ vncserver -kill :1

To modify xstartup file

$ cd ~
$ > .vnc/xstartup
$ nano .vnc/xstartup

With the content

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession
xfce4-session &


If you choose to use other GUIs, replace startxfce4 & accordingly to

  • Gnome-Desktop Environment: gnome-session &
  • KDE-Desktop Environment: startkde &
  • MATE-Desktop Environment: mate-session &
  • LXDE-Desktop Environment: startlxde &
  • Cinnamon-Desktop Environment: cinnamon &
  • Openbox-Desktop Environment: openbox &

Save xstartup when you are done. The next step is to create VNC Server statup script. You must do this with root user

$ su -
# nano/usr/local/bin/myvncserver

With the content

#!/bin/bash
PATH="$PATH:/usr/bin/"
#DISPLAY="1"
DISPLAY="$1"
DEPTH="16"
#GEOMETRY="1024x768"
GEOMETRY="1280x800"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"

case "$2" in
start)
/usr/bin/vncserver ${OPTIONS}
;;

stop)
/usr/bin/vncserver -kill :${DISPLAY}
;;

restart)
$0 stop
$0 start
;;
esac
exit 0


Now make vncserver startup script executable
#chmod +x /usr/local/bin/myvncserver

Script usage:

sudo /usr/local/bin/myvncserver  [N] start
sudo /usr/local/bin/myvncserver [N] stop
sudo /usr/local/bin/myvncserver [N] restart

Where [N] in number of Display

The last step is to make VNC Server starts on boot

# nano /lib/systemd/system/myvncserver.service

With the content

[Unit]
Description=Manage VNC Server on this droplet

[Service]
Type=forking
ExecStart=/usr/local/bin/myvncserver [N] start
ExecStop=/usr/local/bin/myvncserver [N] stop
ExecReload=/usr/local/bin/myvncserver [N] restart
User=[vncuser]

[Install]
WantedBy=multi-user.target

Where [N] in number of Display and [vncuser] is user to start vncserver.

Now we can reload systemctl and enable our service:

# systemctl daemon-reload
# systemctl enable myvncserver.service

If you want to start  another vncserver for another user add  myvncserver2.service with differnet  [N] and [vncuser]

 

Reboot your Debian 8 system and test out your new VNC Server

# reboot

You can login to your remote server via VNC with domain or IP.


Last updated: 14 Giugno 2016 by Pierluigi Minati