VNC stands for Virtual Network Computer. This is a graphical desktop sharing system that uses the Remote Frame Buffer protocol(RFB). There are many software services that provide VNC, among them are TigerVNC, Vino, VNC4server, TightVNC e.t.c
TigerVNC is a free and open-source VNC server that is used to control or access Linux-based desktops remotely. It allows one to interact with graphical applications on remotes systems. This makes it easier for users not yet comfortable with the command-line to manage files, software, and settings on remote servers
This guide will help you install and configure TigerVNC VNC Server on Debian 11 | Debian 10.
Setup Pre-requisites.
To be able to successfully complete this guide, you will need the following:
- A debian 11/10 server
- A local computer where we will install VNC client.
Step 1: Install Desktop Environment on Debian 11/10 Server
By default, Debian 11/10 servers do not have a Desktop Environment. For TigerVNC to be able to control the remote system, we need to have GUI installed on the server. We will add a Desktop Environment to our server as below.
First, we will need to install Tasksel, this tool makes it easy to install a Desktop Environment on a Debian system.
sudo apt update
sudo apt install tasksel -y
With Tasksel installed, we will launch it using the command:
sudo tasksel
You should be able to see this window.
Here, you are free to select, download and install a Desktop Environment of your choice by navigating using the keyboard up and down arrow keys. Select an item using the space key. Your selected item will appear as below with a “*” on it. I chose to use Gnome Desktop in this guide
Press Enter and proceed to the installation. Once the installation is complete, you will be required to set your system to boot into the graphical target.
sudo systemctl set-default graphical.target
Now restart your Debian 11/10 system for the changes made to apply.
sudo systemctl reboot
Step 2: Install TigerVNC Server on Debian 11/10
TigerVNC is available in the default Debian package repository and can be installed easily using the command:
sudo apt install tigervnc-standalone-server tigervnc-common tightvncserver
Dependency Tree:
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libfile-readbackwards-perl
The following NEW packages will be installed:
libfile-readbackwards-perl tigervnc-common tigervnc-standalone-server
0 upgraded, 3 newly installed, 0 to remove and 4 not upgraded.
Need to get 1,126 kB of archives.
After this operation, 3,148 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
With TigerVNC installed, you will be required to set a VNC password to access your desktops.
Switch to the non-root user and set a VNC password. Replace non-root user with your non-root-username
su - non-root-username
vncpasswd
You will be required to set your preferred password as below. Your password should be at least 6 characters.
You will require a password to access your desktops.
Password:Enter your Password
Verify: Re-enter your Password
Would you like to enter a view-only password (y/n)? n
With the above settings made, start the VNC server using the command:
vncserver -localhost no
Sample Output:
/usr/bin/xauth: file /home/thor/.Xauthority does not exist
New Xtigervnc server 'debian.techview.domain.com:1 (debian)' on port 5901 for display :1.
Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /home/debian/.vnc/passwd debian.techview.domain.com:1 to connect to the VNC server.
If it fails to start, run:
tigervncserver -xstartup /usr/bin/xterm
Verify if the tigerVNC service is running
$ vncserver -list
TigerVNC server sessions:
X DISPLAY # RFB PORT # PROCESS ID SERVER
:1 5901 1452 Xtigervnc
Step 3: Configure TigerVNC.
Since we are going to make configuration changes to TigerVNC, we first need to stop the TigerVNC service running on port 5901.
$ vncserver -kill :1
Killing Xtigervnc process ID 1452... success!
Before we make changes to the xstartup file, we need to make a backup of the original file.
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
If the file does not exist, just proceed and create a new xstartup file using the Vim text editor. Install vim on Debian 11/10 using sudo apt install vim
. Here we want to configure TigerVNC to work with our Desktop Environment (Gnome Environment)
vim ~/.vnc/xstartup
This file contains commands that are executed automatically when we start or restart the VNC server. Add the below lines to the file.
For those who used the Gnome Desktop environment, your file should appear as below.
#!/bin/sh
xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &
For those who used the xfce4 desktop environment, your file will be as below.
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Save and exit the file. Make the file executable as below.
sudo chmod u+x ~/.vnc/xstartup
sudo chmod 777 ~/.vnc/xstartup
Start the VNC server.
vncserver
Step 4: Connect to a VNC Desktop Securely.
By default, VNC does not use secure protocols when connecting. In this guide, we will use an SSH tunnel to connect to our Debian 11/10 server. Then we will tell our VNC client to use the tunnel instead of a direct connection.
First, we will create an SSH connection on the local machine that will securely forward the localhost connection for VNC.
On a Linux, macOS terminal execute the below command:
ssh -L 5901:127.0.0.1:5901 -N -f -l debian -t server_ip
In the above code, L- specifies the binding port, here we are binding port 5901 of the remote server to 5901 port on our local machine.
In the code, you need to replace debian with your remote login non-root username and server_ip with the IP Address of your server.
Leave the ssh connection uninterrupted and proceed as below
Now use a VNC client to connect to your remote server. Install a VNC client on the local machine. In this guide, we will use the RealVNC client download it from the official RelaVNC download page
Alternatively, download the package using Wget as below:
##On Debian/Ubuntu
wget https://downloads.realvnc.com/download/file/viewer.files/VNC-Viewer-6.22.207-Linux-x86.deb
##On RHEL/CentOS/Rocky Linux 8
https://www.realvnc.com/download/file/viewer.files/VNC-Viewer-6.22.207-Linux-x64.rpm
Install the downloaded package on your machine:
##On Debian/Ubuntu
sudo apt install ./VNC-Viewer-6.22.207-Linux-x86.deb
##On RHEL/CentOS/Rocky Linux 8
sudo yum localinstall VNC-Viewer-6.22.207-Linux-x64.rpm
While on the official RealVNC downloads page, one can download and install VNC client for Windows, macOS, Linux, Raspberry Pi, iOS, Android, Solaris, HP-UX, and AIX systems.
Launch the VNC client from the local machine terminal as below:
vncviewer localhost:1
You will see this pop-up window.
Click continue. Next, you will see the below window requesting the VNC desktop password set earlier.
With the correct password entered, you will be connected to your remote desktop as below. Enter the password for the username displayed to log in.
While here, you can now manage your file, settings, and any other tasks on your server.
Step 5: Run VNC as a System Service
Now we will configure the VNC server as a systemd service so that we can start, stop and restart the service like any other. This will also allow us to set the service to start automatically on boot.
First, create a systemd file called /etc/systemd/system/[email protected].
sudo vim /etc/systemd/system/[email protected]
In the file, add the below lines and replace your user, group, working directory, and the user in the PID file to match your username
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=debian
Group=debian
WorkingDirectory=/home/debian
PIDFile=/home/debian/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
Save and close the file then reload the daemon.
sudo systemctl daemon-reload
Then enable the service to start automatically on boot.
sudo systemctl enable [email protected]
Stop the running instance:
vncserver -kill :1
Start the VNC service with the command:
sudo systemctl start [email protected]
Check the status of the service:
$ systemctl status vncserver@1
● [email protected] - Start TightVNC server at startup
Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-08-29 05:08:30 EDT; 3s ago
Process: 4948 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=0/SUCCESS)
Process: 4953 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=0/SUCCESS)
Main PID: 4961 (Xtigervnc)
Tasks: 173 (limit: 4915)
Memory: 154.8M
CGroup: /system.slice/system-vncserver.slice/[email protected]
├─4961 /usr/bin/Xtigervnc :1 -desktop debian:1 (debian) -auth /home/debian/.Xauthority -geometry 1280x800 -depth 24 -rfbwait 30000 -rfbauth
├─4967 vncconfig -iconic
├─4968 /usr/lib/gnome-session/gnome-session-binary
├─4971 dbus-launch --exit-with-session gnome-session
├─4972 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
├─4982 /usr/lib/at-spi2-core/at-spi-bus-launcher
├─4987 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
├─4990 /usr/lib/at-spi2-core/at-spi2-registryd --use-gnome-session
├─4993 /usr/lib/gvfs/gvfsd
├─5000 /usr/lib/gvfs/gvfsd-fuse /home/debian/.gvfs -f -o big_writes
├─5022 /usr/bin/gnome-keyring-daemon --start --components=pkcs11
├─5046 /usr/lib/gnome-settings-daemon/gsd-power
................
Start your SSH tunnel again using the command:
ssh -L 5901:127.0.0.1:5901 debian server_ip
Then make a new connection to your Debian 10/11 server using vncviewer localhost:1
. You will now be set to enjoy your remote desktop service using TigerVNC VNC.
Conclusion.
Cheers! You have successfully installed and configured TigerVNC VNC Server on Debian 11 | Debian 10. You can now gain remote Desktop access to your remote Debian 11/10 server.
See more guides:
- Install and Use Guacamole Remote Desktop on Debian
- How To Install MongoDB 5 on Debian
- Upgrade from Debian 10 (Buster) To Debian 11 (Bullseye)