How to Set Up VNC Server on a Linux Machine
Table of Contents
First of all, what is VNC?
In computing, Virtual Network Computing is a graphical desktop-sharing system that uses the Remote Frame Buffer protocol to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical-screen updates back in the other direction, over a network. Wikipedia
Basically it’s a remote desktop controller for all platforms.
I was asked to start a VNC server on a CentOS remote machine, for people to access from Windows laptops. The CentOS server already has
vncserver installed, also I am using conda on it.
For completeness, I shall include a description of how to install VNC server.
- Install a desktop on the remote machine
We often access the remote server without GUI desktop. If it doesn’t have desktop installed, we need to do it ourselves.
$ sudo apt-get install xfce xfce4-goodies -y
or for CentOS:
$ sudo yum -y groups install "GNOME Desktop"
$ sudo apt-get install tightvncserver -y
or on CentOS:
$ sudo yum install tigervnc-server
If the installation is successful, we should be able to run
Start VNC server by running:
Check if it is running by checking the log:
(base) niansong@auros-gaming3e-2:~$ cat ~/.vnc/auros-gaming3e-2\:1.log
Xvnc TigerVNC 1.8.0 - built Nov 2 2018 19:05:14
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12001000, The X.Org Foundation
Wed Feb 24 11:00:32 2021
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5901
vncext: created VNC server for screen 0
GLib-GIO-Message: 11:00:36.261: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications.
Wed Feb 24 11:00:36 2021
ComparingUpdateTracker: 0 pixels in / 0 pixels out
ComparingUpdateTracker: (1:-nan ratio)
If the log looks like this, no error or exiting, we are good.
I got following complain in the log:
gnome-session: WARNING: Could not make bus activated clients aware of
DISPLAY=:7 environment variable: Failed to connect to socket
/tmp/dbus-TAq3EF94t4: Connection refusedß
After trying many methods, I found that it was a dbus conflict casued by conda (who could have thought). We need to uninstall the dbus module in conda:
$ conda uninstall dbus
We need to forward the display port to localhost, and then connect to it with VNC Viewer.
First we run this command:
$ ssh -L 5901:127.0.0.1:5901 -C -N -l <username> <ip>
5901: the port at which
vncserveris running, check it in the log. 5901 is the default number.
<username>is the username you input when running
ipis the server’s ip
In my case:
This command will hang in there, no output is normal. Then we connect to
localhost:5901 on VNC Viewer:
If the connection is successful, we will be able to get the desktop GUI like this: