In the Linux world, VNC is a commonly heard term. The VNC abbreviation stands for Virtual Network Computing. It is a graphical desktop sharing system made to remotely control another computer. VNC is platform-independent, having clients and servers for many operating systems using a graphical user interface (GUI). Learn how to setup VNC server on Ubuntu and how to configure VNC server on Ubuntu.
Prerequisites for Ubuntu VNC setup
Before we start to setup VNC server on Ubuntu, we need to prepare the server by updating the system packages and installing a desktop environment on the server.
Update the system packages:
sudo apt-get update && sudo apt-get upgrade -y
Next, install the Ubuntu Gnome desktop environment:
sudo apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal -y
Note that if you are running a GUI version of Ubuntu, the desktop environment part is not needed in order to install and configure VNC server on Ubuntu.
Setup VNC server on Ubuntu
Now that we updated the system packages and we have a desktop environment, we can continue with the Ubuntu VNC setup by installing the VNC server package.
Install the VNC server:
sudo apt-get install vnc4server -y
Setup VNC server to run on 5901 port or 1 subport:
sudo nano /etc/systemd/system/[email protected]:1.service
Paste the following configuration and replace my user (ciprian) with your server user:
<pre>[Unit] Description=Start VNC4server server at startup After=syslog.target network.target [Service] Type=forking User=ciprian PAMName=login PIDFile=/home/ciprian/.vnc/%H%i.pid #ExecStartPre=/usr/bin/vncserver -kill %i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1024x768 %i ExecStop=/usr/bin/vncserver -kill %i [Install] WantedBy=multi-user.target</pre>
Restart the systemctl daemon using sudo
sudo systemctl daemon-reload
Configure VNC server on Ubuntu
In order to configure VNC server on Ubuntu, we first need to start the VNC server.
Start the VNC server with your current user:
Create a password for the VNC connection. This is the password used to login to your VNC server.
Stop the VNC server:
vncserver -kill :1
Next, we need to configure the desktop environment to load all the required extensions in your Ubuntu VNC setup. Open the xstartup file:
sudo nano /home/ciprian/.vnc/xstartup
Add the following commands to the xstartup file for the desktop environment to load correctly, like in the screenshot below:
gnome-panel & gnome-settings-daemon & metacity & nautilus &
When you configure VNC server on Ubuntu, make sure you configure the VNC server to start automatically. Open crontab and select the second option:
Edit the crontab file as shown:
Add the @reboot /usr/bin/vncserver :1 line to the config file, then press CTRL+X to save the file.
You can now reboot your computer and connect to the VNC Server. Open VNC viewer and enter the server with the subport.
Type the login password.
You are now connected!
The VNC server is now running: What you can do next
Congratulations. Now you can remotely connect to your Ubuntu machine anytime you need to. Next, you can learn how to install Docker on Ubuntu to run apps in containers. If you don;t know about Docker, make sure you check the What is Docker: Docker vs VirtualBox article and learn more about it. Check back soon for more VNC articles.