VNC is a system that allows you to remotely control another computer. It allows you to relay your mouse and keyboard inputs as if you were physically sitting in front of the system, when in fact you could be on the other side of the world. It works well for sharing your desktop screen with another user, whether you want to grant them the ability to control your computer or just be able to see what you are doing on it (with mouse and keyboard input blocked).
In this guide, we will go over the steps to setup a VNC server on a Linux system. You will also see how to use a VNC client to access the shared screen. When we are done, you will be able to access your system remotely from anywhere, provided that your client system and the VNC server have an internet connection. Alternatively, we can configure VNC to be view only, if we want to share the screen without granting control to another user. Both configurations will be covered in this tutorial.
In this tutorial you will learn:
How to install and configure Tiger VNC Server
How to (optionally) configure a Tiger VNC view only password
How to install Tiger VNC Client
How to use Tiger VNC client to connect to VNC Server
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Share your desktop screen with VNC on Linux step by step instructions
First, we will show how to install Tiger VNC on major Linux distros and configure it so that you can share your screen with one or more client systems. The section afterwards will cover the instructions to install Tiger VNC client viewer, and how to connect to the server we configured in the previous section.
Install and Configure Tiger VNC Server
The installation of Tiger VNC server will vary depending on your Linux distro, but the configuration steps should be the same. You can use the appropriate command below to install Tiger VNC with your system’s package manager.
After installation is complete, follow the steps below to set up Tiger VNC Server:
In this step, we will create a VNC config for our current user. If you want to create a new user to use with VNC, use the useradd command and then switch to that user with su before proceeding with the next command.
$ vncpasswd
Enter your desired password twice. Optionally, you can configure a view only password, which will allow someone to connect only to view your desktop.
The next step is to configure some settings for our VNC server. You can use nano or your preferred text editor to create the VNC config file and apply your desired edits to it:
$ nano ~/.vnc/config
We will apply the following configuration to this file:
You can edit the session setting with your desired desktop environment, as long as you have it installed. The geometry settings sets the native resolution of the VNC session and you can adjust it accordingly. Save your config file and exit it when done.
Next, we will assign a default VNC display number to our user. This is can be configured within the vncserver.users file. Use nano or your preferred text editor to open this file with root permissions:
$ sudo nano /etc/tigervnc/vncserver.users
We will assign display number 1 to our user linuxconfig. If you are setting up multiple VNC users, then each one should have their own display number.
# TigerVNC User assignment
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=linuxconfig
Save your changes to this file and exit it when done.
Next, execute the following two systemd commands with root permissions in order to start VNC server for the display number 1 and to make it start up automatically upon future system boots:
Make sure you configure your firewall to allow incoming VNC connections. Since we are configuring display number 1 in this example, we will open port number 5901. Display 2 would use port 5902, etc.
After installation, execute the following command to connect to the VNC server. Of course replace, the IP address below with the IP or hostname of your server you are connecting to:
$ vncviewer 192.168.1.51:1
Note: We have :1 above because that is the display number we configured earlier.
In this tutorial, we saw how to share a desktop screen using VNC on a Linux system. We installed Tiger VNC and configured it to accept incoming connections. This is a great way to allow users secure access to your PC, or for you to administer your system remotely in the future. If you do not want users to be able to share input with your system, and only want them to be able to view, that can be configured with a separate password when executing vncpasswd.