How to Set Up and Use VNC on Raspberry Pi: A Complete Guide for Remote Access

How to Set Up and Use VNC on Raspberry Pi: A Complete Guide for Remote Access

Sep 14, 2024

Raspberry Pi VNC

Why Use VNC on Raspberry Pi?

The primary advantage of using VNC with Raspberry Pi is the flexibility it provides. We can run the Raspberry Pi in "headless mode" (without a physical display) and still have full access to its graphical user interface (GUI). This reduces the need for additional hardware, making setups more affordable and efficient. Whether we’re a hobbyist developing projects, an educator managing a classroom full of Pis, or someone experimenting with IoT devices, VNC offers a user-friendly, customizable way to control and manage the Raspberry Pi remotely.

图片2.png__PID:f56a5c84-9647-4908-b549-b5878ddebf4a

Remote access: Control your Raspberry Pi from anywhere without needing a separate monitor, keyboard, or mouse.
Integration
: VNC is compatible with various operating systems (Windows, macOS, Linux), making it versatile for users with different setups.
Multiple Device Access: Several devices can connect to and control the Raspberry Pi simultaneously, making it useful in collaborative environments.

Step-by-Step Guide to Setting Up VNC on Raspberry Pi

1. Upgrade Raspberry Pi OS Bookworm (IMPORTANT STEP)
Open the terminal and run:
sudo apt-get update
sudo apt-get upgrade
sudo apt full-upgrade
For more information about this commands, visit:
 https://www.sunfounder.com/blogs/news/raspberry-pi-update-essential-steps-for-a-secure-and-optimized-system

2. Enable VNC on your Raspberry Pi:
Open the terminal and run:
sudo raspi-config
Navigate to Interface Options > VNC and select Enable.

图片3.png__PID:7f13cf32-6daf-4299-8e29-de2176057ba9图片4.png__PID:0a7709e2-fed5-4b29-812a-93c2eefe7287

3. Reboot

Connect to Raspberry Pi Using VNC

Download and install VNC Viewer
https://www.realvnc.com/en/connect/download/viewer/

图片5.png__PID:f9412255-9a31-4df1-a339-951d32a0ee4d

1. Open VNC Viewer tool on your computer
2. Go to File > New Connection
Complete VNC Server with your Raspberry Pi IP address

图片6.png__PID:bf3e3dbf-b924-4d01-b76a-2572e67178ad

Raspberry Pi 5, Bookworm and RealVNC Connect

With the release of Raspberry Pi 5 and the transition to the Bookworm (Debian 12) operating system, the setup process for RealVNC Connect (previously RealVNC) has some adjustments compared to earlier versions.

Real VNC official stanament: https://help.realvnc.com/hc/en-us/articles/14110635000221-Raspberry-Pi-5-Bookworm-and-RealVNC-Connect#statement-0-0

At the moment, RealVNC Connect does not support Wayland for Linux systems. If we don't disable Wayland, when we connect to RealVNC Server on these OS we will see a blank/blank screen or a message stating "Cannot currently show the desktop", or find we cannot connect until there is a user logged in on the remote computer. The RealVNC Server GUI may also fail to load.

1. Open Terminal and run the command: 
sudo raspi-config

2. Navigate to > Advanced Options, then select Wayland

图片7.png__PID:472d95b5-05df-4a23-96e0-a83a4ed7af57

3. Select X11

图片9.png__PID:3c310e77-3e55-4545-9ff1-1836d17b7c20

4. Reboot and connect to Raspberry Pi using VNC Viewer

图片10.png__PID:8c92d38c-82be-41e9-8e6b-26702a3ed2a4
Enhancing Your VNC Setup: Security & Performance

Set a VNC Password

We need to set a password that will be used to connect remotely:
1.Open Terminal and run the command: 
Vncpasswd

2.Restart VNC Server
service vncserver-x11-serviced restart

Alternative VNC Password with VNC Connect:

1. Go to Options

图片11.png__PID:a9461741-52f0-4216-b108-85b3bad8ee83

2. Go to Security tab and select Autentication: VNC password

图片12.png__PID:43d00f6d-abb8-4f29-92f0-52caca45f640

3. Select “Standard user” and set the Password then Apply the configuration.

图片13.png__PID:e6ca823c-2c7c-4ea8-ba25-a7aa84eac62d

RealVNC Cloud

If we want to access your Raspberry Pi remotely over the internet (not just on your local network), we’ll need to connect to RealVNC Cloud

1. Create a RealVNC account at RealVNC Connect.
2. Sign in to VNC Server on your Raspberry Pi:

Open VNC Server on your Pi (from the desktop, go to Menu > Preferences > Raspberry Pi Configuration > Interfaces, and ensure VNC is enabled).

Click the VNC icon in the taskbar, and choose Sign In. Enter your RealVNC email and password to sign in.

图片15.png__PID:a7c0c31a-d278-4629-8143-80417c4aa127

3. Access Raspberry Pi from Anywhere:
From VNC Viewer on another device, sign in with the same RealVNC account, and we’ll see your Raspberry Pi listed for remote access.

Solving Common VNC Issues on Raspberry Pi

Black or Blank Screen in Headless Mode

When we connect via VNC without a monitor, the screen appears black or blank.
Set a virtual resolution for the display if the Pi is in headless mode (no monitor attached):
sudo raspi-config

Navigate to Display Options > Resolution, and select an appropriate resolution such as 1280x720.
Alternatively, we can edit the /boot/config.txt file to force a specific resolution:

sudo nano /boot/config.txt
Add or uncomment the following lines:
hdmi_force_hotplug=1
 hdmi_group=2
hdmi_mode=82
sudo reboot

Slow or Laggy VNC Performance

The remote desktop lags or freezes during use.

Network Quality: Ensure both the Raspberry Pi and the device we’re connecting from are on a fast and stable network. If using Wi-Fi, consider switching to Ethernet for a faster and more stable connection.

Change the VNC Encoding Settings
:In the VNC Viewer, go to Options (cog icon) and adjust the encoding. ZRLE or Hextile encodings use less bandwidth but may sacrifice image quality for better performance.

Reduce Screen Resolution
: If the remote desktop experience is slow, try reducing the resolution of your Raspberry Pi display (either in raspi-config or in the desktop settings) to lower the strain on the connection.

Conclusion

VNC is a powerful and flexible tool for remote access to your Raspberry Pi, allowing you to manage projects efficiently without the need for additional hardware. Whether you're working on a local network or accessing your Raspberry Pi from anywhere via the internet, VNC provides a seamless experience. By securing your connections and optimizing performance, you can ensure smooth remote operations. With the steps and tips outlined in this guide, you’ll be well-prepared to fully utilize VNC with your Raspberry Pi.

Raspberry Pi Docker: From Installation to Advanced Usage and Troubleshooting Back to News How to Build an Efficient Raspberry Pi NAS: A Complete Installation and Configuration Guide