Edited 2 weeks ago by ExtremeHow Editorial Team
VNCRemote AccessUbuntuNetworkingLinuxConfigurationOperating SystemsToolsSystemDesktop
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.
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.
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
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.
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.
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.
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
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
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.
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:
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.
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.
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.
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
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
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:
To stop your running VNC server, use:
vncserver -kill :1
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
If you encounter any problems during setup, try these common solutions:
journalctl -xe
.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