In this tutorial, we will learn the commands to install a VNC server on Ubuntu 20.04 LTS Focal or Ubuntu 18.04 Bionic using the terminal to access Gnome Linux graphic user interface, remotely.
What is VNC
VNC stands for Virtual Network Computing is a free and opens source software platform to run on Linux and other operating systems developed by Olivetti & Oracle Research Lab. It enables the Screen content sharing of a remote computer (on which a VNC server is running) on a local computer (on which a VNC viewer is running). Along with the ability to send inputs from keyboard and mouse from local computer to remote PC or server. Just like RDP of Microsoft. However, unlike RDP, the session in VNC will independent, which means the remote user doesn’t need to log out to give access to the client VNC viewer system.
In more clear words, the VNC works on Server-client architecture. The VNC Server part has to be installed on the remote computer that the user wants to access over a network without being physically present in front of it. Whereas the local system from, where the user or admin wants to access the remote system needs to have a VNC viewer app. Then we form one computer will be able to access another computer over a network, which, however, has little in common with normal file sharing.
This remote control software not only enables desktop sharing and application sharing, as long as the network connection is established and the VNC software is running, but no restrictions also have to be accepted.
When do you use VNC software?
The software is suitable for both individuals as well as small to large companies. Usually, network administrators use VNC to solve the problems of employees’ computers by taking remote control via VNC. Most of the time, this is done for troubleshooting purposes without physically attending to the remote computer. Another application is the installation of software via remote access, for which the employee either does not have the appropriate rights or he simply does not have the time.
What are the advantages of using VNC software?
The greatest advantage of using VNC is the saving of time. The administrators or any user doesn’t need to walk through multiple floors to the system where he/she either wants to install any software or just for maintenance.
How to Install VNC Server on Ubuntu 20.04 | 18.04 LTS Linux
The given steps or command will also be the same for the latest Ubuntu 22.04 LTS version, in case you are using that including the distros based on Ubuntu such as Linux Mint.
1. Update APT Repository Cache
The first thing you should do on your system is to run the system update command that will rebuild the system repo cache. Also, if any security or app update is there that will get installed too.
sudo apt update
2. Command to install VNC server on Ubuntu 20.04 | 18.04
Now, no need to add anything extra such as repo because the packages we need to set up a VNC server on Ubuntu 20.04 or 18.04 are already available in their base repository as tigervncserver along with some other needed tools. Hence, just run the given command using APT:
sudo apt install tigervnc-standalone-server tigervnc-xorg-extension sudo apt install xserver-xorg-core
Also, install…
sudo apt install ubuntu-gnome-desktop
Although you would already have Gnome desktop if you are using GUI Ubuntu desktop, still run if there is something new to install or update.
Those were using CLI and just have installed Gnome, they also need to start GDM service.
sudo systemctl start gdm
3. Set VNC password
Now, to access the VNC remotely but safely, set a password for the same. Run:
vncpasswd
It will ask you to enter a new password two times.
4. Run VNC server on Ubuntu 20.04 or 18.04
Now, let’s run the server once to see everything is working fine without giving any error.
vncserver
Also, you will see the display that is used by VNCserver such as here it is :1 and could :1, 2, 3, 4 in your case.
Output in our case:
New 'h2s-VirtualBox:1 (h2s)' desktop at :1 on machine h2s-VirtualBox Starting applications specified in /home/h2s/.vnc/xstartup Log file is /home/h2s/.vnc/h2s-VirtualBox:2.log Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/h2s/.vnc/passwd :1 to connect to the VNC server.
Once you see something like above, that means the server is running without any error:
Kill the server:
vncserver -kill :*
5. Configure Desktop environment for VNC Server
Now, we let the server know which environment it should use to display on the remote screen. Few users prefer to use XFCE, however, here we will go for the default GNOME that comes with Ubuntu Linux distros.
So, let’s create a new Start Script file for the VNC server.
Back up your original XStartup file.
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
Create a new one:
nano ~/.vnc/xstartup
Add the following code in the file:
#!/bin/sh [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources vncconfig -iconic & dbus-launch --exit-with-session gnome-session &
Save the file by pressing Ctrl+O, hit the Enter Key, and exit the same using Ctrl+X.
Change the permission:
sudo chmod +x ~/.vnc/xstartup
6. Start VNC server
Now, start the server with the screen size you want, here we are using 800×600 but you can change as per your need.
vncserver -localhost no -geometry 800x600 -depth 24
7. Access remote system using VNC viewer
Now, we have a server up and running on our Ubuntu 20.04 or 18.04 that we want to access remotely. Thereafter, visit your local windows, Linux or macOS, and install Tiger VNC or any other you want to access the remote system.
Here we are using TigherVNC, here is the page to download the same. Whereas the Linux users can easily install the Viewer using their base repository such as for Debian- sudo apt install tigervnc-viewer
Open TiggerVNC viewer
Enter the IP address along with port 5901 of the remote Ubuntu system where the VNC server is running. example- server-ip:5901
7. Access VNC Server securely over SSH
Those who want to access their remote system securely over ssh, they can follow the given steps.
Install the OpenSSH server on the remote Ubuntu server that you want to access over SSH.
sudo apt install openssh-server -y
Now, open the SSH tunnel for the remote server on the local system. Simply open the command terminal or prompt to run:
ssh server-user@server-ipaddress -C -L 5901:127.0.0.1:5901
Replace server-user and server-IP-address with ones you have on your Ubuntu installed with the VNC server.
After that, again open the VNC viewer app on your local system, and instead of using ip-address:5901
, use localhost:5901
8. Create Systemd service file VNC server (optional)
Those who are interested in using the VNC server as a background service can create a Systemd file for it.
First, kill any existing running instances of the server part:
vncserver -kill :*
After that create a new service file:
sudo nano /etc/systemd/system/[email protected]
Paste the following code:
[Unit] Description= Tiger VNC Server service After=syslog.target network.target [Service] Type=forking User=h2s ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -geometry 800x600 -depth 24 -localhost no :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Save the file by pressing Ctrl+O, Enter key, and then Ctrl+X.
Note: Replace h2s with your current user
9. Start and enable VNC server service on Ubuntu 20.04 | 18.04 (optional)
Once done, start your server as a service:
Here @1 means vncserver :1 – display 1
sudo systemctl start [email protected] sudo systemctl enable [email protected]
To check status:
sudo systemctl status [email protected]
To stop
sudo systemctl stop [email protected]
Other Articles:
• Use RDP on Linux mint to access Windows 11, 10, or 7 remotely
• How to install and configure VNC Server on CentOS 8
• Commands to Install Xrdp Server on Debian 11
• Access AlmaLinux 8 remote desktop using Windows RDP
• How to connect Rocky Linux 8 via Windows
Hello, I have installed Tigervnc like above. It all works till I set the systemd service. I had found I have to reload first and then start. But I keep getting a timeout.
Hello, thank you for the detailed instructions! I feel like I must be doing something wrong, but I can’t figure out what. I am using a raspberry pi 4. I installed 64 bit ubuntu 20.04 and installed the gnome gui. When I get to step 7 and try to connect with TigerVNC from my laptop, I get “unable to connect to socket: No connection could be made because the target machine actively refused it. (10061)”
Any advice would be appreciated. This is my first experience with Pi, so be gentle please!
Please ensure the port number 5901 is opened in your firewall, if enabled.
Grey screen on freshly installed 20.04.
grey screen