15.04.2025

How to Install and Configure VNC on Ubuntu 20.04: Step-by-Step Guide

What is VNC

VNC (Virtual Network Computing) is a software solution that allows you to control a remote system using your local keyboard and mouse as if you were physically present at the remote machine. It’s especially useful for managing servers that have a graphical user interface (GUI).

Requirements to install

To use VNC effectively, a graphical environment on the server is required. While CLI-based remote access is best done with SSH, VNC shines when you need GUI access. Minimum recommended server specifications:

Installation

You're ready now. Please follow steps below:

Update the system and install necessary packages

apt-get update && apt install xfce4 xfce4-goodies tightvncserver

You’ll be prompted to create a password for remote access. Optionally, you can set a separate read-only (viewer) password.

vncserver

Stop the VNC server to configure startup settings

vncserver -kill :1

Configure the startup script and add execution permissions to file:

echo "startxfce4 &" > /root/.vnc/xstartup
chmod +x /root/.vnc/xstartup

 

 

Restart the VNC server

vncserver


To connect, use a VNC client (such as RealVNC or TigerVNC) and enter the IP address of your server followed by the VNC port. Note:

Result like below should appear. If you've seen this - you're great!

Next step is optional: you may want ro run VNC service automatically. It is easy peasy. Create a service initial file:

cat <<EOT > /etc/systemd/system/vnc.service
[Unit]
Description=VNC Server
After=network.target

[Service]
Type=forking
User=root
PAMName=login
PIDFile=/root/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target
EOT

Enable and start the service:

systemctl enable vnc
systemctl start vnc

Conclusion

You’ve successfully installed and configured a VNC server on your Linux machine, allowing you to remotely access your server’s graphical desktop environment. This setup enables seamless management of files, software, and settings with a user-friendly GUI interface, which is especially beneficial when you need to perform tasks that are difficult or impossible through a command-line interface alone. By following the steps in this guide, you've also configured the server to run automatically on system startup, ensuring uninterrupted access to the desktop environment without needing to manually start the VNC service each time. Whether you're managing a server remotely or need to access applications running on a headless machine, this VNC setup is a powerful solution that offers both flexibility and convenience for administrators and users alike.

FAQ (Frequently Asked Questions)