
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. In this tutorial, we will show you how to install and configure VNC on a Debian 9 system.
Prerequisites
You should logged in as a non-root user account with sudo privileges.
Installing the Desktop Environment
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.
First of all need to update the package manager list index:
sudo apt update
Issue the below command to install XFCE package:
sudo apt install xfce4 xfce4-goodies
It will take few moments to be installed.
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.
We are going use and to install TightVNC in this tutorial. Run below command to install TightVNC on your Debian server:
sudo apt install tightvncserver
After that, we need to complete configuration need to generate a configuration file and setup password. Issue below command to generate configuration file:
vncserver
Make sure that you have not used sudo
when generating this file.
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.
Output
You will require a password to access your desktops.
Password:
Verify:
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/tecnstuff/.Xauthority does not exist
New 'X' desktop is debian:1
Creating default startup script /home/tecnstuff/.vnc/xstartup
Starting applications specified in /home/tecnstuff/.vnc/xstartup
Log file is /home/tecnstuff/.vnc/debian:1.log
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.
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
Output
Killing Xtightvnc process ID 1767
Configuring the VNC Server
Now VNC needs to configure to know which graphical desktop it should connect to. To do it generate a new file using:
nano ~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Make changes as above after that save and close file.
we’ll need to make ~/.vnc/xstartup
file executable so to use startup file properly. Run the below command:
sudo chmod +x ~/.vnc/xstartup
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/tecnstuff/.vnc/xstartup
Log file is /home/tecnstuff/.vnc/debian:1.log
Connecting 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.
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:127.0.0.1:5901 -C -N -l username your_server_ip
It will ask you to enter password so enter it and hit Enter key to continue. On above command replace username with your real username
and your_server_ip
with your remote server ip address.
Set Up SSH Tunnel on Windows
PuTTY is SSH client for Windows, using that you can set SSH tunnel. Follow the below steps:
Start PuTTY application on Windows and enter ip address in Host name or IP address textbox.

Now go to Connection > SSH > Tunnels
menu option. It show as given below screenshot. 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.

Again go back to session tab and save this settings so it can be used next time. Now you just need to select saved session and click on open button to remote server.
Connect using Vncviewer
Now every configuration is made properly and time to 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. Open your VNC viewer, enter server ip address with port :5901
and hit on the Connect button.

You will be ask you to enter password so enter it and you will see the default Xfce desktop as below:

Finally, you are successfully connected to your server via VNC. You also can interact using mouse and keyboard to your server.
Conclusion
You have successfully installed VNC on your server and configured. Also, you learned how to connect it from Linux, MacOS and Windows local system and manage your Debian 9 server easily using a graphic interface.
Leave a Reply