How to Install and Configure VNC on Debian 10/11

How to Install & Configure VNC Server on Debian

VNC (Virtual Network Computing) is a protocol that enables one to access the graphical desktop of a remote PC over a network connection. In addition, it allows sending keyboard and mouse signals to the remote PC, thus making tasks like managing files, applying configurations, and installing software much more accessible.

In this post we will give you a step-by-step guide on how to install VNC on Debian 10 or Debian 11, how to connect to your Debian machine via VNC, and how to install multiple popular desktop environments and switch between them.

We will divide this post into two main sections.

  • Installing VNC on Debian 10/11 Desktop (running the GNOME Desktop environment)
  • Installing VNC on Debian 10/11 Server (Has no Desktop Environment installed)

Let’s dive in and get started.

Install and Configure VNC on Debian 10/11

If you are running Debian 10 or 11 Desktop, which comes with the GNOME 3 Desktop Environment, follow this section’s instructions.

There are different types of VNC servers available today. GNOME 3 comes with a default VNC server known as Vino. Unfortunately, as of writing this post, Vino doesn’t support the GNOME display server, Wayland. Therefore, we will need to use another display server like X11 for you to run Vino VNC on GNOME.

Don’t panic! You won’t need to install X11 as it’s already installed. All we need to do is switch the display server of choice in the Login screen. Follow the instruction below.

Switch to X11 Display Server

If you were already logged in on Debian, log out as shown in the image below.

word image 43

Once logged out, we need to log in again. However, this time you will need to tweak some default settings. Just before entering your password, click on the gear icon next to the Sign-in button. On the list of Desktop Environments that appear, select GNOME on Xorg as shown in the image below to set our default display server to X11.

word image 44

Once done, enter your password and Log in. You are now using the X11 Display server.

Install Vino VNC

By default, Vino VNC comes preinstalled on GNOME 3 Desktop. However, if that’s not the case for you, install Vino VNC by executing the commands below on your Terminal.

sudo apt update
sudo apt install vino -y

word image 45

Enable Screen Sharing

Once we have Vino VNC installed, we now need to set up Screen sharing on our system. By default, GNOME 3 uses Vino to enable screen sharing over a network. So first, launch the Settings app and select Sharing. Next, click on the Toggle button at the top to allow sharing, as shown below.

word image 46

Once you have enabled Sharing, click on Screen Sharing, as shown below.

word image 47

A small window will pop up where you will set all your screen-sharing settings. First, enable Screen Sharing by click on the toggle button at the top-left. Next, you will see an option whether you want the VNC connections to control the screen or use the View-only mode. In my case, I will check the box since I need to interact with the remote desktop.

Below that, you can set the Access options whether you want the new incoming connection to always ask for access or use a password. We will use the Require a Password option and set our desired password for this post. Any device that wants to connect will need to authenticate using a password. Lastly, you can enable Wired Connections under the Networks menu.

word image 48

Find the IP Address

To access our remote machine over VNC, we will need to know its IP address. You can do from the Terminal by running the command below:

hostname -I

word image 49

From the image above, we can see my Debian system is assigned the IP 192.168.1.46.

Access your PC via VNC with Vinagre

There are many VNC clients available for today. For this post, however, we will use Vinagre VNC. If you don’t have it installed on your Linux PC, use the command below to install it:

sudo apt install vinagre

After a successful install, Launch the Vinagre application from the Apps menu, now renamed to Remote Desktop Viewer.

word image 50

On the Vinagre main window, click Connect, and a window will pop up, as shown below. Set the protocol as VNC and enter the remote machine IP address. You can set other additional settings from the options below. Once done, click Connect.

You will be required to authenticate using a password to establish a VNC connection.

word image 51

From the image below, you can see we have successfully established a VNC connection.

word image 52

That’s it! You have learned how easy it is to set up the VNC server on your Debian 10 Desktop and access it from a remote machine with a VNC client like Vinagre.

Install and Configure VNC on Debian 10/11 Server

In the previous section, we looked at installing and configuring the VNC server on Debian Desktop running the GNOME 3 Desktop Environment. In this section, we will look at how to install and configure VNC on Debian 10/11 server. So let’s dive in and get started!

Install a Desktop Environment

Just like most Linux servers, Debian 10/11 server doesn’t come pre-installed with a Desktop environment. Therefore, we will need to install one to access our server using a graphical interface and not the usual command line. We will install the XFCE Desktop Environment (DE). It is one of the lightest Linux DEs and doesn’t take up so much of the server resources compared to a DE like GNOME.

Assuming you have command-line access to your server, execute the commands below:

sudo apt update
sudo apt install task-xfce-desktop dbus-x11

word image 53

You might be required to select the desired keyboard layout you want from the list during the installation process. Select the one you are comfortable with and hit Enter.

Install the VNC Server

There are many VNC server software available for Linux systems. In this post, we will install the TightVNC server. Then, execute the command below on your server.

sudo apt install tightvncserver

Once TightVNC installs successfully, we will perform the initial VNC configuration and set up the verification password. Then, execute the command below on the server.

vncserver

You will see a prompt to set up a password that to access your remote Desktops. Please note, this password is between six and eight characters. Any password of more than eight characters will be truncated to eight characters.

Once done, you will see the prompt,Would you like to enter a view-only password? Any connections that connect to the VNC server with this password will not interact with the Desktop using the keyboard or mouse. So it’s a reliable option if you are presenting/demonstrating something to many people. For this post, however, we will not need it. So I will enter n for NO.

word image 54

The VNC server will generate several configuration files and show you the connection information.

Configure the VNC Server

Every time you launch the VNC server, it needs to know which exact commands and services to start. Specifically, it needs to know which Desktop Environment it needs to connect to. All these configurations are in the xstartup file found in the .vnc directory created when you first run the vncserver command.

By default, when you first launch the VNC server, it will launch an instance on port 5901 referred to by the VNC as :1. When you launch other instances for any additional computer that wants to connect, it will use ports 5902, 5903, and so on. These ports will be referred to as :2, :3 and so on.

To get started performing these configurations, we first need to kill the VNC instance we launched by executing the command below:

vncserver -kill :1

word image 55

Now, we will start configuring the VNC server. First, create a backup of the original xstartup file as shown below, then create a new one and open it with the nano editor. Execute the command below:

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
sudo nano ~/.vnc/xstartup

On the open nano editor, paste the lines below.

#!/bin/sh
# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/usr/bin/startxfce4
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

When done, save the file (Ctrl + O, then Enter) and Exit (Ctrl + X). Now to apply the changes, we need to make this file executable and launch the vncserver. Execute the commands below:

sudo chmod +x ~/.vnc/xstartup
vncserver

word image 57

Up to this point, your VNC server is configured successfully, and you can even connect to it (unsecured) from a VNC client on your local PC. Just get your server’s IP address using the hostname -I command and use it to connect to your VNC server.

In my case, I am using the Vinagre VNC client to connect to my server. You can easily install Vinagre using the commands below:

sudo apt install vinagre -y

word image 58

I have successfully connected to my server from my local PC (unsecured), as you can see from the image below. I emphasize the term unsecured because VNC by itself doesn’t implement any security protocols.

word image 59

Connecting to the VNC Desktop Securely

Since VNC alone doesn’t use any protocols, we will create an SSH tunnel to connect to our VNC instance running on the server. If you are on a Linux system or macOS, execute the command below:

ssh -L 5901:127.0.0.1:5901 -C -N -l johndoe debian_server_ip

Let’s briefly discuss the command above:

  • -L: This parameter specifies the port bindings we are using. In this case, we are binding the remote port (5901) to our local PC(127.0.0.1) port (5901).
  • -C: This parameter enables compression of data sent over the network.
  • -N: This parameter tells SSH not to execute any remote commands.
  • -l: This parameter shows the login name to use for the VNC server.
  • Replace johndoe with the non-root user on your server and debian_server_ip with your servers’ IP address.

When you execute the command, you will be required to enter the login password of your server. If the connection were successful, the SSH session would remain open, as shown in the image below:

word image 60

Leave the session open as it is and proceed to launch Vinagre. This time around, we won’t use the servers’ IP address to connect to our VNC instance. Instead, we will use our localhost address and bind it to port 5901, as shown in the image below.

word image 61

When you click Connect, you will be required to enter the password you set when you first launched the VNC server. From the image below, you can see I have successfully established a VNC connection to my remote server.

word image 62

That’s it! You have installed VNC on your Debian 10/11 server and successfully established a Remote Desktop connection from your local PC. However, we can do one more thing to automate the VNC setup process – run the VNC server as a service.

Run the VNC Server as a Service

By setting up VNC as a service, you can quickly start, stop or restart it as you would do for any other service running on your server. We will also add it to the startup applications list so that VNC is automatically started even after a reboot.

To get started, execute the command below to create a new unit file using the nano editor.

sudo nano /etc/systemd/system/[email protected]

Paste the lines below and remember to replace the highlighted text accordingly.

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=johndoe
Group=johndoe
WorkingDirectory=/home/johndoe

PIDFile=/home/johndoe/.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

word image 63

Save the file (Ctrl + O, then Enter) and Exit (Ctrl + X).

Now, execute the commands below to make the system aware of the new unit file.

sudo systemctl daemon-reload
sudo systemctl enable [email protected]

word image 64

Now you can start VNC just like any other service and even check its status. However, first, kill the running instance of the VNC server.

vncserver -kill :1
sudo systemctl start [email protected]
sudo systemctl status [email protected]

word image 65

That’s it! You have successfully set up VNC as a service and even added it to the startup applications. From now on, the service will automatically start even after a reboot. Enable SSH tunneling again and connect to your remote server via a graphical desktop session.

ssh -L 5901:127.0.0.1:5901 -C -N -l johndoe debian_server_ip

Configure VNC to Use Other Desktop Environments (And Changing Between Them)

Configure VNC to Use GNOME

Install GNOME on Debian:

sudo apt install task-gnome-desktop dbus-x11

To configure VNC to use GNOME edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/gnome-session

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using GNOME.

This is how GNOME looks on my Debian 11 machine:

word image 89

Configure VNC to Use XFCE

Install XFCE on Debian:

sudo apt install task-xfce-desktop dbus-x11

To configure VNC to use XFCE edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/startxfce4

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using XFCE.

This is how XFCE looks on my Debian 11 machine:

word image 90

Configure VNC to Use LXQt

Install LXQt on Debian:

sudo apt install task-lxqt-desktop dbus-x11

To configure VNC to use LXQt edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/startlxqt

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using LXQt.

This is how LXQt looks on my Debian 11 machine:

word image 91

Configure VNC to Use LXDE

Install LXDE on Debian:

sudo apt install task-lxde-desktop dbus-x11

To configure VNC to use LXDE edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/startlxde

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using LXDE.

This is how LXDE looks on my Debian 11 machine:

word image 92

Configure VNC to Use MATE

Install MATE on Debian:

sudo apt install task-mate-desktop dbus-x11

To configure VNC to use MATE edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/mate-session

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using MATE.

This is how MATE looks on my Debian 11 machine:

word image 93

Configure VNC to Use Budgie

Install Budgie on Debian:

sudo apt install budgie-desktop dbus-x11

To configure VNC to use Budgie edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/budgie-session

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using Budgie.

This is how Budgie looks on my Debian 11 machine:

word image 94

Configure VNC to Use KDE Plasma

Install KDE Plasma on Debian:

sudo apt install task-kde-desktop dbus-x11

To configure VNC to use KDE Plasma edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/startplasma-x11

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using KDE Plasma.

This is how KDE Plasma looks on my Debian 11 machine:

word image 95

Configure VNC to Use Cinnamon

Install Cinnamon on Debian:

sudo apt install task-cinnamon-desktop dbus-x11

To configure VNC to use Cinnamon edit the ~/.vnc/xstartup file (or create a new one if it doesn’t already exist) and add paste in the following:

~/.vnc/xstartup
#!/bin/sh

# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/cinnamon-session

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

Now restart the VNC server and next time you connect you should be using Cinnamon.

This is how Cinnamon looks on my Debian 11 machine:

word image 96

Conclusion

This post has given you a step-by-step guide on installing and configuring the VNC server on Debian 10/11 machine, and how to install multiple desktop environments and switch between them. You can now easily manage your remote system over a graphical interface instead of the regular command line. You now even have the ability to run graphical applications like Gparted remotely. If you have any feedback or questions, feel free to leave a comment or contact us and we’ll get back to you as soon as we can.

21 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tomas
Tomas
3 months ago

Hello!
Firts guide that actually got it to work for me.
But i have one big problem, when i connect to the vncserver i don’t se the desktop, just a big grey screen, do you know how i can fix that?
Tomas

You May Also Like