Installing VNC Server on Debian/Ubuntu

You can use a graphical interface to manage a Linux server. You can do this by installing a graphical interface and then using a VNC server.

Since the operation of a VNC server via public IP address can possibly create security gaps, we recommend the use of an SSH tunnel or a VPN connection to establish the VNC connection. In our tutorial we will discuss the possibility of the SSH tunnel.

1. Update the system

First, the system should be updated to the latest package versions:
apt-get update; apt-get upgrade

2. LXDE GUI and VNC Server Installation

Then install LXDE and VNC Server:

apt-get install lxde tightvncserver xkb-data-i18n


3. Configuration of the VNC server

To write the basic configuration, first start the VNC server once (the VNC server asks for a password for access). Please note that the VNC server is started here as user root. It is safer to create an extra user for the start of the VNC server.Start the VNC server with the command:

tightvncserver :1

After the start, the configuration file was created, which must now be adjusted. The VNC server is stopped and the configuration file is edited:

tightvncserver -kill :1
nano ~/.vnc/xstartup
touch ~/.Xresources
Insert the following lines at the end of the file:
lxterminal &
/usr/bin/lxsession -s LXDE &
This is to start LXDE, the configuration file should look something like this:
#!/bin/sh
export XKB_DEFAULT_RULES=base
export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
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
lxterminal &
/usr/bin/lxsession -s LXDE &

If everything is entered correctly, restart the VNC server:

tightvncserver :1
The desktop is now accessible with a VNC client at the address: <IP address>:5901

4. Disable power saving options

On some servers, the problem occurs after installation that the server enters the energy saving mode / standby after time X. To prevent this, newer systems must
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
This disables the power saving mode.

5. Connection via SSH tunnel

First, the VNC server should no longer listen for connections via the public IP.

 

To do this, stop the VNC server and start it with the parameter "-localhost":
tightvncserver -kill :1
tightvncserver :1 -localhost

 

On Linux, the connection can then be started using SSH with the following command:
ssh -f -N -L 5901:localhost:5901 root@<serverip>

 

On Windows, you can open the SSH tunnel using the Putty program by starting Putty and expanding the SSH tab in the menu. Enter there on tunnel at source port 5901" and at destination localhost:5901". Then press the button "Add" and go back to Sessions to connect.

 

The desktop is now accessible with a VNC client at localhost:5901.

 
Tags