News
3 new Serverspace GPT API Language Models available now!
VB
April 10 2025
Updated April 15 2025

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

Ubuntu VNC

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:

  • At least 2 GB RAM
  • 2 CPU cores
  • 20–30 GB of disk space

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

pic1

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

vncserver

pic2

Stop the VNC server to configure startup settings

vncserver -kill :1

pic3

Configure the startup script and add execution permissions to file:

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

pic4

 

 

Restart the VNC server

vncserver

pic7
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:

  • Display :1 corresponds to TCP port 5901
  • Display :2 corresponds to TCP port 5902, and so on.

pic7

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

pic8

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

pic9

Enable and start the service:

systemctl enable vnc
systemctl start vnc

pic10

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)

  • Q: What if I want to use a different desktop environment (e.g., GNOME, KDE)?
    A: Replace xfce4 with the appropriate package (e.g., gnome-session, kde-plasma-desktop) and update the startup script accordingly.
  • Q: Can I change the display port (e.g., from :1 to :2)?
    A: Yes, when starting VNC, use vncserver :2 to start on display 2 (port 5902).
  • Q: Is VNC encrypted by default?
    A: No, VNC is not encrypted. It’s recommended to tunnel VNC over SSH for secure usage.
  • Q: How can I access the server from Windows?
    A: Download a VNC client (like RealVNC or TightVNC), enter the server IP and port (e.g., 192.168.1.100:5901), and use the access password you created.
  • Q: I get a black screen or errors on connection. What should I do?
    A: Make sure your desktop environment is correctly set in .vnc/xstartup and the script is executable.
Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.