Language: EN

vnc-en-linux-lxde

Set up VNC on Linux with LXDE

In this post we are going to set up a VNC remote service on a Linux environment with LXDE and TightVNC. LXDE is an open source desktop environment for Unix systems, which stands out for its clean interface and lightness. These characteristics make it a very suitable desktop to install on mini PCs such as Raspberry PI, Cubierboard, and similar devices.

In the case of Raspbian, the most common distribution on Raspberry PI, it is easy to configure a VNC server because it has simplified tools for this. However, in general in other distributions, such as Lubuntu, it is not so simple because it requires certain manual configurations.

INSTALL FILES

First, we open a terminal window and type the following to update the repositories.

apt-get update & apt-get upgrade

Next, we install the necessary LXDE Core files and the TightVNC Server.

apt-get install xorg lxde-core lxde-icon-theme tightvncserver

Finally, we run TightVNC server to test its operation and create the configuration files correctly.

/usr/bin/tightvncserver :1 -geometry 1024x768 -depth 16 -pixelformat rgb565

If at any time we want to stop TightVNC, we use

tightvncserver -kill :1

START DESKTOP ON CONNECTION

If we start TightVNC and connect at this moment, we would only see a gray screen. This is because it is necessary to configure VNC to start the LXDE desktop when connecting. To do this, we run the following command to edit the VNC configuration file.

nano  ~/.vnc/xstartup

We add the following line at the end of the file

lxterminal & /usr/bin/lxsession -s LXDE &

We save changes and close the file

START ON SYSTEM BOOT

We could already connect with our computer. But if at any time the computer is turned off or restarted, the server would become unavailable. We would have to connect via SSH beforehand and start TightVNCServer. To avoid this, we are going to configure the system to start TightVNC Server on boot.

To do this we write the following command.

nano /etc/init.d/tightvncserver

We add the following code


#!/bin/sh

## Change username by the user you want to run this under
export USER='username'

eval cd ~$USER

case "$1" in
  start)
    su $USER -c ‘/usr/bin/tightvncserver :1 -geometry 1024x768 -depth 16 -pixelformat rgb565′
    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

Next, we save changes and close. Finally, we enter the following command.

sudo chmod 775 /etc/init.d/tightvncserver
update-rc.d tightvncserver defaults

The next time we restart our machine, TightVNC server will start automatically, and we will be able to connect, starting the LXDE environment when starting the session.