Install and Configure VNC on Debian 9 - Step by Step Process ?

VNC stands for Virtual Network Computing. It is graphical desktop sharing system that allows you to use your keyboard and mouse to interact with a remote server. Using it you can manage files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related VNC queries.

In this context, we shall look into how to install and configure VNC on a Debian 9 system.

How to Install the Desktop Environment on Debian ?

Before proceeding with this Installation procedure, ensure that you are using a user with sudo privileges.

By default, graphical desktop environment does not installed on your Debian system. At first, you need to install a lightweight desktop environment. There are many desktop environments available in Debian repositories. 

Out of most popular available desktop environments, XFCE is the quite lightweight. It is fast, stable and uses low amount of memory.

1. First of all need to update the package manager list index:

$ sudo apt update

Then, run the below command to install XFCE package:

$ sudo apt install xfce4 xfce4-goodies

This Installation process will take a few moments.

How to Install VNC Server on Debian ?

There are many VNC servers available in Debian repositories like TightVNC, TigerVNC and x11vnc. Each have own advantages and disadvantages in terms of security and speed.

Here, We are going use and to install TightVNC

1. Run below command to install TightVNC on your Debian server:

$ sudo apt install tightvncserver

2. After that, we need to complete configuration need to generate a configuration file and setup password. 

3. Execute below command to generate configuration file:

$ vncserver

It will prompt to enter and verify a password to access your desktop remotely. It will also ask for whether to set password as a view-only password. If you have set up a view-only password then you will not be able to interact with the remote desktop with mouse and keyboard.

You will require a password to access your desktops.
Would you like to enter a view-only password (y/n)?
Warning: debian:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server debian:1
xauth:  file /home/linuxapt/.Xauthority does not exist
New 'X' desktop is debian:1
Creating default startup script /home/linuxapt/.vnc/xstartup
Starting applications specified in /home/linuxapt/.vnc/xstartup
Log file is /home/linuxapt/.vnc/debian:1.log

4. After run the vncserver command for first time, it will generate and store password file in ~/.vnc directory.

When VNC is first set up, it launches a default server instance on port 5901. This port is called a display port, and is referred to by VNC as :1. VNC can launch multiple instances on other display ports, like :2, :3, and so on.

5. Because we are going to be changing how the VNC server is configured, first stop the VNC server instance that is running on port 5901 with the following command:

$ vncserver -kill :1
Killing Xtightvnc process ID 1777

How to Configure the VNC Server ?

Now VNC needs to configure to know which graphical desktop it should connect to. 

1. To do it generate a new file using:

$ nano ~/.vnc/xstartup
xrdb $HOME/.Xresources
startxfce4 &

2. Make changes as above after that save and close file.

3. We'll need to make ~/.vnc/xstartup file executable so to use startup file properly. 

Run the below command:

$ sudo chmod +x ~/.vnc/xstartup

4. Now, restart the VNC server by typing:

$ vncserver

It will show output as below:

New 'X' desktop is debian:1
Starting applications specified in /home/linuxapt/.vnc/xstartup
Log file is /home/linuxapt/.vnc/debian:1.log

How to Connect to VNC server ?

VNC is not using any secure protocols when make connection. So it's advisable way to use an SSH tunnel to connect securely to our server. Thus, it will forward traffic securely from local client system to host system.

How to Set Up SSH Tunnel on Linux and macOS ?

For Linux, macOS or any other Unix-based operating system on your machine, you can simply create an SSH tunnel using following command:

$ ssh -L 5901: -C -N -l username your_server_ip

It will ask you to enter password so enter it and hit Enter key to continue. Using the above command replace username with your real username and your_server_ip with your remote server ip address.

How to Set Up SSH Tunnel on Windows ?

PuTTY is SSH client for Windows, using that you can set SSH tunnel. Follow the below steps:

1. Start PuTTY application on Windows and enter ip address in Host name or IP address textbox.

2. Now go to Connection > SSH > Tunnels menu option. 

3. Now enter VNC server port (5901) in the Source Port field and enter server ip address along with port :5901 in the Destination field and click on Add button.

4. Again go back to session tab and save this settings so it can be used next time. 

5. Now you just need to select saved session and click on open button to remote server.

How to Connect using Vncviewer ?

Now every configuration is made properly and you can connect VNC server using Vncviewer at localhost:5901 host. 

There are many Vncviewer like TigerVNC, TightVNC, RealVNC, UltraVNC Vinagre and VNC Viewer for Google Chrome, you can use any of then to connect.

Here we are going to use TightVNC

1. Open your VNC viewer, enter server ip address with port :5901 and hit on the Connect button.

2. You will be ask you to enter password so enter it and you will see the default Xfce desktop.

3. Finally, you are successfully connected to your server via VNC. 

You also can interact using mouse and keyboard to your server.

[Need assistance in fixing VNC connection issues on any Linux Distribution? We can help you. ]


This article covers how to install and configure VNC on Debian Linux System. Also, you will learn how to connect it from Linux, MacOS and Windows local system and manage your Debian 9 server easily using a graphic interface.
VNC (Virtual Network Computing) is a technology for remote desktop sharing. VNC enables the visual desktop display of one computer to be remotely viewed and controlled over a network connection. It is similar to MSTSC on windows. It uses the Remote Frame Buffer protocol (RFB) to remotely control another computer.

To install VNC and XFCE on Debian, run the following commands:

$ apt-get update
$ apt-get install xfce4 xfce4-goodies gnome-icon-theme tightvncserver

To Create a VNC User on Debian:
1. Create a user named vnc by using this command.

$ adduser vnc
2. Install sudo by executing this command. We will need to add vnc user to sudo group.
$ apt-get install sudo
3. Now, Add vnc user to sudo group, it will give permission to vnc user to act like a root user and execute root command.
$ gpasswd -a vnc sudo
Adding user vnc to group sudo
4. switch to a vnc user for further operations.
$ su - vnc