Install and Configure VNC on Debian: Full Guide
that allows you to use your keyboard and mouse to interact with a
graphical desktop environment on a remote server. It helps users who are
not yet comfortable with the command line with managing files,
software, and settings on a remote server.
In this guide, you’ll set up a VNC server with TightVNC
on a Debian 11 server and connect to it securely through an SSH tunnel.
Then, you’ll use a VNC client program on your local machine to interact
with your server through a graphical desktop environment.
To follow this tutorial, you’ll need:
- One Debian 11 server set up by following the Debian 11 initial server setup guide, including a non-root user with access and a firewall.
Code: Select all
sudo - A local computer with a VNC client installed that supports VNC connections over SSH tunnels.
- On Windows, you can use TightVNC, RealVNC, or UltraVNC.
- On macOS, you can use the built-in Screen Sharing program, or can use a cross-platform app like RealVNC.
- On Linux, you can choose from many options, including ,
Code: Select all
vinagre, RealVNC, or TightVNC.Code: Select all
krdc
Step 1 — Installing the Desktop Environment and VNC Serverhttps://www.digitalocean.com/community/ ... vnc-server
By default, a Debian 11 server does not come with a graphical desktop
environment or a VNC server installed, so you’ll begin by installing
those.
You have many options when it comes to which VNC server and desktop
environment you choose. In this tutorial, you will install packages for
the latest Xfce
desktop environment and the TightVNC package available from the
official Ubuntu repository. Both Xfce and TightVNC are known for being
lightweight and fast, which will help ensure that the VNC connection
will be smooth and stable even on slower internet connections.
After connecting to your server with SSH, update your list of packages:
Code: Select all
sudo apt updateCode: Select all
xfce4-goodiesCode: Select all
sudo apt install xfce4 xfce4-goodiesmanager for Xfce. A display manager is a program that allows you to
select and log in to a desktop environment through a graphical
interface. You’ll only be using Xfce when you connect with a VNC client,
and in these Xfce sessions you’ll already be logged in as your non-root Debian user. So for the purposes of this tutorial, your choice of display manager isn’t pertinent. Select either one and press
Code: Select all
ENTEROnce the installation completes, install the TightVNC server:
Code: Select all
sudo apt install tightvncserverCode: Select all
dbus-x11Code: Select all
sudo apt install dbus-x11Code: Select all
vncserverCode: Select all
vncserverCode: Select all
OutputYou will require a password to access your desktops.
Password:
Verify:with more than eight characters will be truncated automatically.
Once you verify the password, you have the option to create a
view-only password. Users who log in with the view-only password will
not be able to control the VNC instance with their mouse or keyboard.
This is a helpful option if you want to demonstrate something to other
people using your VNC server, but this isn’t required.
The process then creates the necessary default configuration files and connection information for the server:
Code: Select all
OutputWould you like to enter a view-only password (y/n)? n
xauth: file /home/sammy/.Xauthority does not exist
New 'X' desktop is your_hostname:1
Creating default startup script /home/sammy/.vnc/xstartup
Starting applications specified in /home/sammy/.vnc/xstartup
Log file is /home/sammy/.vnc/your_hostname:1.logStep 2 — Configuring the VNC Serverhttps://www.digitalocean.com/community/ ... vnc-server
The VNC server needs to know what commands to execute when it starts
up. Specifically, VNC needs to know which graphical desktop it should
connect to.
These commands are located in a configuration file called
Code: Select all
xstartupCode: Select all
.vncCode: Select all
vncserverWhen VNC is first set up, it launches a default server instance on port
Code: Select all
5901Code: Select all
:1Code: Select all
:2Code: Select all
:3Because you are going to change how the VNC server is configured, first stop the VNC server instance that is running on port
Code: Select all
5901Code: Select all
vncserver -kill :1Code: Select all
OutputKilling Xtightvnc process ID 17648Code: Select all
xstartupCode: Select all
mv ~/.vnc/xstartup ~/.vnc/xstartup.bakCode: Select all
xstartupCode: Select all
nano ~/.vnc/xstartupor restart the VNC server. You need VNC to start your desktop
environment if it’s not already started. Add the following commands to
the file:
Code: Select all
~/.vnc/xstartupCode: Select all
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &- : The first line is a shebang.
Code: Select all
#!/bin/bash
In executable plain-text files on *nix platforms, a shebang tells the
system what interpreter to pass that file to for execution. In this
case, you’re passing the file to the Bash interpreter. This will allow
each successive line to be executed as commands, in order. - : This command tells VNC’s GUI framework to read the user’s
Code: Select all
xrdb $HOME/.Xresourcesfile.Code: Select all
.Xresourcesis where a user can make changes to certain settings for the graphicalCode: Select all
.Xresources
desktop, like terminal colors, cursor themes, and font rendering. - : This command tells the server to
Code: Select all
startxfce4 &
launch Xfce. This is where you will find all the graphical software that
you need to comfortably manage your server.
Code: Select all
nanoCode: Select all
CTRL+XCode: Select all
YCode: Select all
ENTERTo ensure that the VNC server will be able to use this new startup file properly, you need to make it executable:
Code: Select all
sudo chmod +x ~/.vnc/xstartupCode: Select all
vncserverCode: Select all
OutputNew 'X' desktop is your_hostname:1
Starting applications specified in /home/sammy/.vnc/xstartup
Log file is /home/sammy/.vnc/your_hostname:1.log