My time
 
My weather
Lugano

Partly cloudy
Temp.: 25°C
Humid.: 30%
 
About this blog
 
Blogroll
 
My Company
 

How to install VNC on Debian

Published on Friday, November 1st, 2013 by Maurizio Mutti

The problem

On Linux operating system, installing and configure VNC is not like a breeze as in Windows.
Here some extra configuration is needed to make the VNC server start automatically and impersonate a specific user.

The goals of this tutorial are the following:

  • Install tightVNC Server
  • Configure it to have a specific user desktop with X interface when connecting
  • Made the server start automatically at system boot

The solution

First of all we need to install the VNC server, to instal TightVNC server use the following command:

sudo apt-get update
sudo apt-get install tightvncserver

Then we verify the basic installation works, to do this we launch the VNC server with a resolution of 1440×900 pixels on desktop 1, using this command:

vncserver :1 -geometry 1440x900

And we connect to the server with the client setting the connection to IPAddress:Desktop.
If the connection works and we can see the X user interface, everything went fine and we can proceed.

We have now to setup the VNC server to run on boot, to accomplish this we create the file vncboot in /etc/init.d containing the following instructions:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          tightvncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop tightvncserver
### END INIT INFO

### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
### End customization required

eval cd ~$USER

case "$1" in
start)
su $USER -c '/usr/bin/tightvncserver :1 -geometry 1440x900 -depth 24'
echo "Starting TightVNC server for $USER "
;;
stop)
pkill Xtightvnc
echo "Tightvncserver stopped"
;;
*)
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
;;
esac
exit 0

Modify the file permissions so it can be executed

chmod 755 /etc/init.d/vncboot

Enable dependency based boot sequencing

update-rc.d /etc/init.d/vncboot defaults

If it says:

update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot

then try the following command

update-rc.d vncboot defaults

The last change needed is to allow su command to be executed for our user without the need of a password, this is done modifying the file /etc/sudoers adding the line:

username ALL=NOPASSWD:/usr/bin/vncserver

Restart the Linux machine and after restart it should be possible to connect to it.

TIP: With some VNC’s versions arrow keay does not work fine when on a terminal, to fix this disable shortcuts in:
Application -> System tools -> Preferences -> System settings -> Keyboard -> Shortcut -> Window

Bibliography

I would like to thanks all the authors of the following articles to have explained various expect of the topic.

  1. Installing VNC
  2. RPi VNC Server
  3. Giving sudo with no password to a user in Debian
Share

Leave a Reply