How to Enable Remote Desktop Ubuntu using VNC (Step by Step Tutorial)

How to Enable Remote Desktop Ubuntu using VNC (Step by Step Tutorial). In this guide, we will introduce VNC, its uses, advantages then move onto the VNC server and installation phase. After following this guide, you can easily set VNS server on your Ubuntu machine and manage it remotely over the internet.

Shall we start with How to Enable Remote Desktop Ubuntu using VNC (Step by Step Tutorial).

What is VNC Server?

VNC, or Virtual Networking Server, is a remote desktop sharing system that lets you control another computer in another location. These tools are lightweight and versatile, making them one of the best remote desktop software. VNC server makes managing files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

Apart from controlling another computer in different places, it also helps to:

  • Control machines and devices using server programs and client/viewer programs.
  • Run on several operating systems.
  • Transmit your mouse and keyboard functions to the remote computer.

Common Uses Of VNC Server

Today, Virtual Networking System is used in two ways: to access remotely from the comfort of your home or through remote technical support that takes over the computer for support activities.

Remote Workers

Several companies enable workers to work remotely using the VNC server desktops. Offers some security so that employees do not have to take the documents and emails of the company with them. All they can do is log into their working computer and start working on the data given in it.

Business Continuity Processes (BCP)

Companies encounter multiple disasters, making physical access to the workspace impractical. However, with the help of VNC, the necessity for physical access is removed from the computer, and workers can continue working without any interruptions.

Remote Technical Support

VNC is considered the perfect solution for remote technical support. It is because it enables a remote technician to control your desktop. The best part about this is that the person requiring support does not have to be knowledgeable.

Features of VNC Server

Developed in the ’90s, the VNC server is a mature product that operates on a very robust but simple protocol known as Remote Framebuffer Protocol. It is essentially platform independent as the mechanism used to transport desktop images, and keyboard presses back and forth exist under the operating system. Although a separate operating system client and server is required, there are VNC clients and server clients for every operating system virtually, including mobile phones.

VNC Server Advantages

  • Provides intuitive mouse control.
  • Gives tried and tested performance.
  • Supports all major operating systems, such as Linux, MacOS and Windows.
  • Delivers both attended and unattended access.
  • Pre installs and connects on demand.
  • It is highly secure.
  • Provides multilingual support. 

This is the main part of How to Enable Remote Desktop Ubuntu using VNC (Step by Step Tutorial) .

How to Enable Remote Desktop Ubuntu using VNC

Prerequisites

  • A root user or a user with sudo privileges.

Install TigerVNC Server

TigerVNC is a free and open source Virtual Network Computing (VNC) server and client software. It works on client/server architecture and allows users to launch and interact with graphical applications on remote machines.

Additionally TigerVNC package is included in the Ubuntu main repository. You can install it by just running the following command:

				
					apt install tigervnc-standalone-server -y
				
			

After installing the TigerVNC server package, you can verify the package information using the following command:

				
					apt-cache policy tigervnc-standalone-server
				
			

You should get the package information in the following output:

				
					tigervnc-standalone-server:
  Installed: 1.7.0+dfsg-8ubuntu2
  Candidate: 1.7.0+dfsg-8ubuntu2
  Version table:
 *** 1.7.0+dfsg-8ubuntu2 500
        500 http://in.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        100 /var/lib/dpkg/status
				
			

At this point, the TigerVNC server is installed on your Ubuntu machine. You can now proceed to create a VNC user.

Create a User for VNC

Next, you will need to create a user and set a password for it. You can create a user named user1 by running the following command:

				
					adduser user1
				
			

You will need to set a password during the user creation as shown below:

				
					Adding user `user1' ...
Adding new group `user1' (1000) ...
Adding new user `user1' (1000) with group `user1' ...
Creating home directory `/home/user1' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for user1
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] Y

				
			

Next, log in to the user1 with the following command:

				
					su - user1
				
			

Once you are logged in, set a password for VNC with the following command:

				
					vncpasswd
				
			

You will be asked to set a password as shown below:

				
					Password:
Verify:
Would you like to enter a view-only password (y/n)? n
				
			

After setting up a password for the VNC server, you can procee to start the VNC server.

Start the VNC Server

At this point, VNC server is installed on your Ubuntu system. You can now start the VNC server with the following command:

				
					vncserver -localhost no 
				
			

You should see the following output:

				
					New 'ubuntu:1 (user1)' desktop at :1 on machine ubuntu

Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/user1/.vnc/ubuntu:1.log

Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /home/user1/.vnc/passwd ubuntu:1 to connect to the VNC server.

				
			

You can also verify your running VNC server with the following command:

				
					vncserver -list 
				
			

You should see your active VNC server in the following output:

				
					TigerVNC server sessions:

X DISPLAY #	RFB PORT #	PROCESS ID
:1		5901		31028
				
			

Once you are done, you can proceed to installing and configuring VNC client.

Install VNC Client

After installing and setting up VNC server. You will need to install the VNC client package on the remote machine where you want to connect your VNC server.

1.First, download the VNC client package from the RealVNC website with the following command:

				
					wget https://downloads.realvnc.com/download/file/viewer.files/VNC-Viewer-6.22.515-Linux-x64.deb
				
			

2. After the successfull download. You can install it by running the following command:

				
					dpkg -i VNC-Viewer-6.22.515-Linux-x64.deb
				
			

3. After installing the VNC client, you can launch it from the application menu. You should see the VNC Viewer in the following screen:

4. Click on the File => New connection to create a new VNC connection. You should see the following screen:

5. Provide your VNC server IP, connection name and click on the OK button. You should see your created VNC connection on the following screen:

6. Now, double click on your VNC connection. You will be prompt to enter your VNC server password. After the successful authentication, you should see your remote Ubuntu desktop screen:

7. If you want to stop your VNC server. You can stop it with the following command:

				
					vncserver -kill :1
				
			

At this point, your VNC server is running and accessible from the remote machine. However, for the production environment, it is recommend to create a dedicated service file to start and stop the VNC service. 

Manage VNC Service with Systemd

It is a good idea to create a systemd service file to manage the VNC service. So you don’t need to start VNC manually. You can create it with the following command:

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

Add the following code:

				
					[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=user1
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :
ExecStart=/usr/bin/vncserver :%i -localhost no -geometry 1024x768
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

				
			

Save and close the file when you are don. Then, run the following command to apply the configuration changes:

				
					systemctl daemon-reload 
				
			

Next, start the VNC service with the following command:

				
					
systemctl start vncserver@1.service 
				
			

Please enable the VNC service so it starts automatically after the system reboot.

				
					systemctl enable vncserver@1.service 
				
			

You can also check the VNC status with the following command:

				
					systemctl status vncserver@1.service 
				
			

You will get the status of the VNC service in the following output:

				
					● vncserver@1.service - Remote desktop service (VNC)
     Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Tue 2022-09-06 13:23:01 UTC; 3s ago
    Process: 33304 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
    Process: 33329 ExecStart=/usr/bin/vncserver :1 -localhost no -geometry 1024x768 (code=exited, status=0/SUCCESS)
    Process: 33409 ExecStop=/usr/bin/vncserver -kill :1 (code=exited, status=0/SUCCESS)
   Main PID: 33329 (code=exited, status=0/SUCCESS)

Sep 06 13:23:00 ubuntu systemd[1]: Starting Remote desktop service (VNC)...
Sep 06 13:23:00 ubuntu systemd[33304]: pam_unix(login:session): session opened for user user1 by (uid=0)
Sep 06 13:23:00 ubuntu systemd[1]: Started Remote desktop service (VNC).
Sep 06 13:23:00 ubuntu systemd[33329]: pam_unix(login:session): session opened for user user1 by (uid=0)
Sep 06 13:23:01 ubuntu systemd[33409]: pam_unix(login:session): session opened for user user1 by (uid=0)
Sep 06 13:23:01 ubuntu systemd[1]: vncserver@1.service: Succeeded.

				
			

Configure VNC for Gnome Desktop

By default, VNC does not works with the Gnome desktop environment. So you will need to create a xstartup configuration file in your VNC users home directory and define some configurations: This fill will runs automatically whenever you start or restart the VNC server.

Firstly, login with your VNC user with the following command:

				
					su - user1
				
			

Next, create a VNC configuration file using the nano editor:

				
					nano ~/.vnc/xstartup 
				
			

Add the following configurations:

				
					#!/bin/sh
exec /etc/vnc/xstartup
xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &
				
			

Save and close the file after you done. Then, provide the executable permission to the file:

				
					chmod u+x  ~/.vnc/xstartup 
				
			

Thank you for reading How to Enable Remote Desktop Ubuntu using VNC. We shall conclude.

How to Enable Remote Desktop Ubuntu using VNC Conclusion

In this post, we showed you how to enable the remote desktop on Ubuntu using VNC. You can now use VNC to access and manage your Ubuntu desktop machine remotely over the internet. VNC is very useful for system administrator and customer support executive to perform their tasks remotely over the web.

Why don’t you take a look at more Ubuntu content here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x