How To Setup VNC For Ubuntu 24.04
Welcome to the Greenhost.cloud blog! Today, we’ll be diving into a step-by-step guide on setting up VNC (Virtual Network Computing) on Ubuntu 24.04. VNC enables remote desktop access, allowing you to control your desktop environment from anywhere, making it a handy tool for system administrators or anyone who needs to access their machine remotely. So, let’s get started!
What is VNC?
VNC is a graphical desktop-sharing system that uses the Remote Frame Buffer protocol to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction over a network. VNC is available for a variety of platforms and is especially popular among Linux users.
Prerequisites
Before we start, ensure you have:
- A server or computer running Ubuntu 24.04.
- Sudo privileges on the machine.
- An active internet connection.
We will also need to install a desktop environment if it’s not already set up and a VNC server. For this guide, we’ll use TigerVNC, a popular VNC server.
Step 1: Update Your System
Open your terminal and ensure that your package list and installed packages are updated:
sudo apt update
sudo apt upgrade
Step 2: Install a Desktop Environment
If your Ubuntu installation doesn’t have a desktop environment (common for server installations), you can install one. Ubuntu 24.04 default version comes with GNOME, but you can also choose to install others like XFCE for a lightweight option.
To install XFCE, run:
sudo apt install xfce4 xfce4-goodies
Step 3: Install TigerVNC
Now, we need to install the TigerVNC server:
sudo apt install tigervnc-standalone-server tigervnc-common
Step 4: Set Up VNC Password
You must set a password for VNC access. This password secures your VNC sessions.
Run the following command:
vncpasswd
You’ll be prompted to enter and verify a password. Optionally, you can set a view-only password, but this is not mandatory.
Step 5: Configure VNC Server
You need to create a configuration file for the VNC server. First, start VNC once to generate the configuration files:
vncserver
This command will create a default configuration directory at ~/.vnc/
, including the file xstartup
. You can now stop the VNC server:
vncserver -kill :1
Next, edit the xstartup
configuration file:
nano ~/.vnc/xstartup
Replace the content with the following lines to start the XFCE desktop:
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
Make the xstartup
file executable:
chmod +x ~/.vnc/xstartup
Step 6: Start the VNC Server
You can now start the VNC server:
vncserver
Take note of the display number (e.g., :1
), as you will need to use this when connecting.
Step 7: Configure Firewall for VNC
If your server has a firewall enabled, you need to open the appropriate ports. VNC typically runs on port 5900
. For example, if your display number is :1
, you will need to open port 5901
.
Run the following commands:
sudo ufw allow 5901/tcp
Step 8: Connect to the VNC Server
You can use any VNC client (like RealVNC, TigerVNC Viewer, or TightVNC) on your local machine. Open your VNC client and enter your server’s IP address followed by the display number. For example:
your_server_ip:1
Then, enter the VNC password you set earlier, and you should have access to your remote Ubuntu desktop!
Step 9: (Optional) Configure VNC as a Systemd Service
To ensure that VNC starts automatically when the server boots, you can set it up as a systemd service.
Create a new service file:
sudo nano /etc/systemd/system/[email protected]
Add the following content to the file, replacing <USER>
with your username:
[Unit]
Description=VNC Server for %i
After=display-manager.service
[Service]
Type=forking
User=<USER>
PIDFile=/home/<USER>/.vnc/%H:%i.pid
ExecStart=/usr/bin/vncserver %i -geometry 1280x800 -depth 24
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save and exit the editor. Then, enable and start the VNC service:
sudo systemctl daemon-reload
sudo systemctl enable [email protected]
sudo systemctl start [email protected]
Conclusion
Congratulations! You’ve successfully set up a VNC server on your Ubuntu 24.04 machine. With this setup, you can easily access your desktop environment from anywhere in the world.
For more tutorials and insights about cloud hosting and technology, stay tuned to the Greenhost.cloud blog!