AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Install a VNC Server under Ubuntu 22.04: Tutorial

PARTAGEZ

The installation of a VNC Server Ubuntu 22.04 gives you the possibility of accessing to your Linux office from wherever you are. Whether working at home, traveling or simply from another room, a VNC Server gives you access to your workspace at any time.

What are the advantages of a VNC Server Ubuntu 22.04?

A VNC Server Ubuntu 22.04 offers many possibilities that greatly simplify daily work. A VNC Server allows you to access your Ubuntu office from anywhere in the world. This means that you don't need to be at your workstation to manage your applications and data. This flexibility is extremely practical for teleworkers, traveling professionals or all those who wish to work from different places. The configuration of the VNC Server is particularly simple, so that even less computer -keen users can quickly establish a remote connection that works.

A VNC Server also facilitates interaction within the teams. It allows several members to access the same office simultaneously. This allows teams to collaborate effectively, work together on projects and solve problems in real time, wherever they are. Systems and networks administrators as well as IT support services can also resolve errors remotely without having to go there. This saves time, travel costs and appointments. In terms of security, many VNC Server Ubuntu 22.04 have robust options. Costed connections and different authentication methods protect data and prohibit system access to unauthorized persons.

The prerequisites for a VNC Server Ubuntu 22.04

First, Ubuntu 22.04 must be installed and operate perfectly. Many VNC Servers are entirely compatible with this operating system and all the necessary packages and outbuildings are available in Ubuntu official deposits. Make sure your system is up to date to avoid complications during installation. The following requirements should be met:

  • Ubuntu 22.04: A recent and perfectly functional installation of Ubuntu 22.04
  • Connection to the network: a stable ethernet or wifi connection for remote access
  • Root authorization: The super-user of a VNC Server needs root rights for installation and configuration.
  • Software: An installation of VNC Server software like Tigervnc, Realvnc or X11VNC from Ubuntu deposits.
  • Office environment: An office environment (for example Gnome, XFCE) must be installed.
  • Firewall configuration: opening of port 5900 or adjustment of firewall rules to authorize VNC traffic

Instructions step by step: Installation of a Ubuntu VNC Server 22.04

When you choose your VNC Server and your office environment, many options are available to you. In this tutorial, we will install the latest packages for the XFCE office environment and the Tigervnc package, available in the Ubuntu deposit. XFCE and Tigervnc both require a few resources and offer good performance. This allows the VNC connection to remain fluid and stable, even if the Internet connection is slow.

Step 1: Update the packages

Before you start installation, make sure your system is up to date. Run the following commands to install all the available updates:

sudo apt update
sudo apt upgrade

bash

Step 2: Install the office environment

The VNC Server needs an office environment because it makes the office available via the network. Ubuntu 22.04 comes by default with Gnome, but you can install other office environments like XFCE which is very little resource.

sudo apt install xfce4 xfce4-goodies

bash

The package xfce4-goodies Contains additional tools and plug-ins useful for XFCE.

Step 3: Create a new user

After installing the office environment, you must create a new user to operate the VNC Server. It is advisable not to do it as superuser to guarantee security. We will therefore create a new user named « John » and give him the necessary authorizations for the VNC Server to work under this user account.

At first, you must create the user « John » and assign him a password. To do this, use the following commands:

sudo useradd -m -s /bin/bash john
sudo passwd john

bash

Order sudo useradd -m -s /bin/bash john Creates the “John” user and installs a personal directory, the shell being defined by default on /bin/bash. Then use sudo passwd john To define a password for this user. It is imperative to choose a safe password.

After creating the user, add him to the Sudo group so that he can execute administrative orders. To do this, use the following command:

sudo usermod -aG sudo john

bash

This command allows « John » to execute orders with extensive rights using Sudo.

To verify that « John » has good authorizations, connect as « John » and test the Root rights. To do this, run these orders:

Order su - john Allows you to go to the user « John » and the command sudo su Allows you to obtain root rights, provided that the password has been properly entered. If the authentication is successful, a command prompt such that root@hostname appears, attesting that you have the rights of administrator.

Step 4: Install VNC Server software

Here we use Tigervncbecause it is a widespread and well supported VNC server option. Install Tigervnc with this command:

sudo apt install tigervnc-standalone-server tigervnc-common tigervnc-tools

bash

This command installs the VNC Server software as well as certain packages necessary for its operation.

Step 5: Create the VNC Server instance

Before you can start the VNC server, first define a password that will allow access to the VNC server. Type the following command in the terminal:

You will be invited to indicate a password and confirm it. This password protects access to your VNC Server. You can also choose an option to define a password View-only If you want other users to see the screen but do not have control.

At the first start of the server, a new display is created, typically :1. This output indicates the exact number of the display you can use.

Here is an example:

New 'X' desktop is your-machine-name:1

bash

Note the display number (in this case :1). You will need it to connect to the VNC Customer.

Step 6: Configure the VNC Server instance

Create a configuration file for the VNC Server to be sure that XFCE is loaded at the start of the VNC Server. The file ~/.vnc/xstartup may, for example, have the following content:

#!/bin/sh
# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/usr/bin/startxfce4
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &

bash

The file becomes executable when using the following command:

chmod +x ~/.vnc/xstartup

bash

Step 7: Execute the VNC Server as a system service

By configuring the VNC Server as a Systemd service, you can start, stop it and restart it like any other service. In addition, you can use the Systemd commands so that the VNC Server automatically launched the system startup.

First create a new file with the text editor of your choice:

nano /etc/systemd/system/vncserver@.service

bash

Add the following content to the file:

[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=
PAMName=login
PIDFile=/home//.vnc/%H:%i.pid
ExecStart=/usr/bin/vncserver %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target

bash

Replace by your real username. Load the new service file and activate the service:

sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@:1

bash

Order sudo systemctl enable vncserver@1.service Active the VNC Server service for display :1 so that it automatically starts when starting the system. To do this, we call on the Systemd service file vncserver@.servicein which %i is replaced by 1. This allows you to configure the VNC Server for the display :1 And to ensure that it is launched each time the system starts. The command creates the shortcuts necessary to include the service in the right starting process.

Step 8: Configure the firewall

If you have activated a firewall on your VNC Server Ubuntu, you must unlock the VNC port in order to allow remote connections. The VNC Server uses Port 5900 by default, followed by the display number. For display :1the port is therefore 5901.

Authorize the port with the command ufw ::

sudo ufw allow 5901/tcp

bash

Check the firewall settings and make sure the port is open:

Here is an example of a possible answer:

Status: active
To                              Action        From
--                                ------            ----
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                   ALLOW       Anywhere
5901/tcp                 ALLOW       Anywhere
22/tcp (v6)              ALLOW       Anywhere (v6)
80/tcp (v6)              ALLOW       Anywhere (v6)
443/tcp (v6)            ALLOW       Anywhere (v6)
5901/tcp (v6)          ALLOW       Anywhere (v6)

bash

Step 9: Connect to the VNC Server

To connect to your VNC Server, you need a customer VNC on your local computer. Popular customer VNCs are Realvnc, Tigervnc Viewer and Tightvnc Viewer. To improve the safety of your VNC connection, plan to use a quantified connection via SSH. This protects communication between your VNC Customer and the VNC Server.

Establish a connection to your server via SSH and redirect the VNC port:

ssh -L 59000:localhost:5901 -C -N -l @

bash

  • ssh : command for secure connection to a remote server via the SSH protocol which transmits the data in a quantified manner.
  • -L 59000:localhost:5901 : Activates local port redirect; Port 59000 traffic on your local computer is redirected by the SSH tunnel to port 5901 on the remote server. localhost Refers to the remote server on which the VNC Server turns.
  • C : Activates compression of data traffic; This can improve transmission speed and reduce the use of bandwidth, especially in the case of slow connections.
  • N : prohibits the execution of orders on the remote server; This mode is useful if you only want to create the tunnel without throwing Shell on the remote server.
  • -l : Indicates the username with which you connect to the remote server.
  • : the IP address or the host name of the remote server to which you wish to connect via SSH.

Note

Replace by your username and by the IP address of your server.

Connect to the local 5901 port that you transferred via the SSH tunnel by entering localhost:5901 In your VNC Viewer.

This method guarantees that your VNC connection is made via a encrypted SSH connection to make it safer.

Step 10: Manage the VNC Server

To stop or restart the VNC Server, use the following commands:

Stop the VNC Server:

Restart the VNC Server:

Close the VNC Server (with Systemd):

sudo systemctl stop vncserver@:1

bash

Status verification:

sudo systemctl status vncserver@1

bash

A possible answer could be:

vncserver@1.service - Start TigerVNC server at startup
      Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
      Active: active (running) since Mon 2024-07-29 16:57:26 UTC; 20s ago
     Process: 97088 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)
     Process: 97092 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :1 (code=exited, status=0/SUCCESS)
    Main PID: 97103 (Xtigervnc)
        Tasks: 77 (limit: 4665)
      Memory: 146.7M
          CPU: 4.459s
      CGroup: /system.slice/system-vncserver.slice/vncserver@1.service
. . .

bash

Step 11: Troubleshooting

If you encounter problems, check the following points:

  • Newspaper files: Log files for the VNC Server can be found in ~/.vnc. Check that these files do not contain error messages that can indicate any problems.
  • Network connections: Make sure that no network or firewall restriction blocks access to the VNC port.
  • Configuration files: Check that the file ~/.vnc/xstartup does not contain configuration errors of the office environment.

You can now easily manage your files, programs and system settings via a VNC Server. If you prefer to use Windows, we recommend our tutorial « Install a VNC Server on Windows ».

Dedicated servers

Performance and innovation

Take advantage of your own server, with dedicated hardware, cloud integration, minute invoicing and Intel® Xeon® or AMD processor.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact