Share your desktop screen with VNC on Linux

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
Share your desktop screen with VNC on Linux
Share your desktop screen with VNC on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Tiger VNC
Other 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.

To install Tiger VNC on Ubuntu, Debian, and Linux Mint:

$ sudo apt update
$ sudo apt install tigervnc-common tigervnc-standalone-server tigervnc-tools tigervnc-viewer tigervnc-xorg-extension

To install Tiger VNC on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install tigervnc tigervnc-icons tigervnc-server tigervnc-server-module tigervnc-selinux

To install Tiger VNC on Arch Linux and Manjaro:

$ sudo pacman -S tigervnc

After installation is complete, follow the steps below to set up Tiger VNC Server:

  1. 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.

    Create a new password to use with Tiger VNC
    Create a new password to use with Tiger VNC



  2. 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
    
  3. We will apply the following configuration to this file:
    session=gnome
    geometry=1920x1080
    localhost
    alwaysshared
    

    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.

  4. 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
    
  5. 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.

  6. 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:


    $ sudo systemctl start tigervncserver@:1
    $ sudo systemctl enable tigervncserver@:1
    
  7. Check to make sure that the service is running:
    $ sudo systemctl status tigervncserver@:1
    
    The Tiger VNC Server process is running on our system and listening for incoming connections
    The Tiger VNC Server process is running on our system and listening for incoming connections
  8. 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.
    UFW (Ubuntu):
    $ sudo ufw allow 5901/tcp
    
    Firewalld (Fedora / RHEL):
    $ sudo firewall-cmd --zone=public --add-port=5901/tcp
    
    iptables (any distro):
    $ sudo iptables -A INPUT -m state --state NEW,ESTABLISHED -m tcp -p tcp --dport 5901 -j ACCEPT
    

Install and Connect With Tiger VNC Client

You can use the appropriate command below to install Tiger VNC client with your system’s package manager.

To install Tiger VNC on Ubuntu, Debian, and Linux Mint:

$ sudo apt update
$ sudo apt install tigervnc-viewer




To install Tiger VNC on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install tigervnc

To install Tiger VNC on Arch Linux and Manjaro:

$ sudo pacman -S tigervnc

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.

Using VNC client to connect to the VNC server and share desktop
Using VNC client to connect to the VNC server and share desktop

Closing Thoughts




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.



Comments and Discussions
Linux Forum