How To Install and Setup VNC Server On Linux
Virtual Network Computing or simply popular name VNC is a protocol mostly used by Linux servers to create remote desktop connection. VNC is also used for different operating systems like MacOS, Windows, Unix, BSD etc. There are different VNC client and server sides applications like TightVNC, TigerVNC, RealVNC etc. We will prefer VNC application provided by Ubuntu distribution which is TightVNC.
Desktop Environment is group of applications used to provide GUI desktop experience to the user. There are different Desktop Environments like GNOME, KDE, Xfce, LXDE etc. In this tutorial we assume you have all ready install one of those desktop environment. VNC server will provide installed Desktop Environments. If there is no desktop environment or it is not configured correctly generally a black screen will appear.
As we stated before we will install VNC server into Ubuntu. We assume that we have an existing Desktop as stated previously. We will install tightvncserver package from Ubuntu yaketty but alternative VNC servers or alternative distributions can be installed with similar steps like below. As we will install app we need root privileges which can be provided with
sudo or with root user.
$ apt install tightvncserver/yakkety -y
VNC Server Configurations
The most error prone and important part of the setup of VNC Server is configuration part. We will run
vncserver command and follow the steps.
We will provide a password for the current user vncserver session. There is also an verification step to be sure password in entered correctly.
We have configured VNC Server and created session number 1 which is stated as
ubu2:1 with the host name. Here ubu2 is the hostname and 1 is the session number which also specifies a port.
VNC server ports starts from tcp 5900 by default and session number is added to find related port number. For example session 1 is tcp port 5900+1=5901 .
Connect To VNC Server
To connect VNC server we need some VNC client in the client computer. There is no problem if the client and server applications are different. In this situation we use Tightvnc client too. First open client.
And put the host and session information like above
ubu2:1 . There is also alternative expression format by provided port number directly like
ubu2:5901 . And click connect. There is also
Options part which is used to configure connection parameters like window size, compression algorithm, compression ratio, cursor behavior etc.
We should enter password in to the provided box like below.
And we will get our desktop if there is no problem
Connect With Ssh Tunnel
By default VNC is not an encrypted protocol. This can create security problems. One of the steps to take in order to make more secure is tunelling via encrypted channels like ssh tunnels. Ssh encrypted and secure protocol. Ssh provides tunneling which can be used for all network streams and connections. Following command will create a secure channel between client and server.
$ ssh -L 5901:127.0.0.1:5901 -N -f ismail@ubu2
-L 5901:127.0.0.1:5901will bind our localhost port number
5901to the remote ssh server local port
-Nused to do not execute remote command
-fused to send ssh to the background
ismail@ubu2used to provide user
Kill VNC Server
Killing will just stop provided session and do not kill whole VNC server or other sessions do not provided. There is a practical command which will use session number like below.
$ vncserver -kill :1