WindowsMacSoftwareSettingsSecurityAndroidProductivityLinuxPerformanceAppleConfiguration All

How to set up and use Virtual Network Computing (VNC) on Ubuntu

Edited 2 weeks ago by ExtremeHow Editorial Team

VNCRemote AccessUbuntuNetworkingLinuxConfigurationOperating SystemsToolsSystemDesktop

How to set up and use Virtual Network Computing (VNC) on Ubuntu

This content is available in 7 different language

Virtual Network Computing (VNC) is a graphical desktop-sharing system that uses the Remote Frame Buffer Protocol (RFB) to remotely control another computer. It transmits keyboard and mouse input from one computer to another, and relays graphical-screen updates over the network. This article will guide you step-by-step through the process of setting up and using VNC on an Ubuntu system. We will also discuss some additional configurations to help you run a secure and efficient VNC session. By the end of this tutorial, you will have a fully functional VNC server running on your Ubuntu machine that you can access via a VNC client from anywhere.

1. Setting up VNC server

The first step to setting up VNC on Ubuntu is to install a VNC server. We will be using TigerVNC server, which is one of the most popular VNC server implementations. It is famous for its performance and is open source.

1.1 Update your system

It is always a good practice to update the system package repository and installed packages before starting any new setup. Open the terminal on your Ubuntu system and run the following command:

sudo apt update && sudo apt upgrade -y

1.2 Install TigerVNC server

Now, we will install the TigerVNC server package. Execute the following command:

sudo apt install tigervnc-standalone-server -y

This command will download and install TigerVNC Server along with all required dependencies on your system.

1.3 Set secure VNC password

Once you have TigerVNC installed, the next step is to set the password for the VNC server. The VNC password is independent of your user password and provides an additional layer of security. Run the following command to set the password:

vncpasswd

You will be asked to enter a password and confirm it. This password will be required to connect to the server from the client machine.

2. Configure the VNC server

After installing TigerVNC, it is important to configure it properly for effective operation. This includes setting up the display manager and the window manager/desktop environment that we will be accessing via VNC.

2.1 Setup the desktop environment

For a full graphical environment, you will need to install a desktop environment. Ubuntu has several desktop environments, such as Gnome, XFCE, and KDE. If you have not installed any, we suggest you use XFCE as it is lightweight and performs well with VNC. You can install XFCE using the following:

sudo apt install xfce4 xfce4-goodies -y

2.2 Create a VNC configuration file

Now, create a VNC configuration file to define how the VNC server should initiate a session. You can write your own custom configuration file:

nano ~/.vnc/xstartup

Add the following to the xstartup file:

#\!/bin/bash xrdb \$HOME/.Xresources startxfce4 &

Make sure the xstartup file is executable:

chmod +x ~/.vnc/xstartup

3. Start the VNC server

At this point, you are ready to start the VNC server that will host your desktop environment. To start the VNC server, use the command:

vncserver -localhost no :1

:1 indicates display port 5901. VNC uses port 5900+N, where N is the display number. localhost no flag allows remote VNC connections.

4. Connect to a VNC server

Now that your VNC server is up and running, you'll need to connect to it from a VNC client on another computer. Here's how you'd do that:

4.1 Download and install a VNC client

To access your VNC server, you will need a VNC client application on your local machine. Some popular VNC clients include TigerVNC Viewer, RealVNC, and TightVNC. Download and install your chosen VNC client.

4.2 Establish a connection to the VNC server

Once your VNC client is installed, open it and connect to the server using the server's IP address or hostname and then the display port. For example:

192.168.1.10:1

Upon establishing the connection, you will be asked to enter the password you set earlier. Enter your VNC password, and you will gain access to the remote Ubuntu desktop.

5. Secure VNC connection using SSH

VNC connection data is not encrypted by default, so using a Secure Shell (SSH) tunnel to secure data transmission between your local machine and the VNC server is a recommended practice.

5.1 Setup the SSH server

If the SSH server isn’t already running on your Ubuntu machine, install it:

sudo apt install openssh-server -y

Make sure the SSH server is running by using the following:

sudo systemctl status ssh

5.2 Establish SSH tunnel

To set up an SSH tunnel, use the following command on your local machine:

ssh -L 5901:127.0.0.1:5901 -N -f -l your_username your_server_ip

Don't forget to replace your_username and your_server_ip with your specific details. Once the tunnel is established, connect your VNC client to it:

127.0.0.1:5901

6. Manage and stop the VNC server

Managing your VNC server includes stopping it when not needed, restarting it, or making sure it runs automatically when you boot. Here's how you can manage your VNC sessions:

6.1 Stop the VNC server

To stop your running VNC server, use:

vncserver -kill :1

6.2 Automatically start VNC server on boot

To run the VNC server automatically when the system starts, create a systemd service file:

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

Add the following lines:

[Unit] Description=Start TightVNC server at startup After=syslog.target network.target [Service] Type=simple User=your_username PAMName=login PIDFile=/home/your_username/.vnc/%H%i.pid ExecStart=/usr/bin/vncserver -fg -localhost no :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target

Replace your_username with your actual username. Enable the service:

sudo systemctl enable vncserver@1.service

7. Troubleshooting

If you encounter any problems during setup, try these common solutions:

Conclusion

We have successfully set up and used virtual network computing on Ubuntu. By installing and configuring a VNC server, setting up password-authenticated sessions, tunneling VNC traffic over SSH, and managing VNC server operations, you have unlocked a new level of remote desktop capability. Remember that optimizing security should always be a priority, especially when dealing with remote access tools.

With these instructions, you are now ready to connect to your Ubuntu machine from anywhere, gaining more flexibility and control over your digital workspace. Expand your freedom by exploring different desktop environments and configurations to best suit your remote computing needs. Happy remote computing!

If you find anything wrong with the article content, you can


Comments