How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04

Photo by Jainath Ponnala on Unsplash

If you have Ubuntu Server installed on your Raspberry Pi and you want to connect to its interface without a monitor or mouse?
Then you have come to the right place!

After all, here are instructions on how to inst…


This content originally appeared on DEV Community and was authored by Okinea Dev


Photo by Jainath Ponnala on Unsplash

If you have Ubuntu Server installed on your Raspberry Pi and you want to connect to its interface without a monitor or mouse?

Then you have come to the right place!

After all, here are instructions on how to install the Gnome graphical interface and how to connect to it via VNC

First of all. we need to update the packages using below command:



sudo apt update && sudo apt upgrade


After that, we will already install the minimal Gnome shell (you need to download ~350 MB):



sudo apt install gnome-core


Next, install the TigerVNC server and other add-ons for its operation:



sudo apt install tigervnc-standalone-server xserver-xorg-core xserver-xorg-video-fbdev


Now that we have installed the graphical shell and all the other packages, we can now start configuring the VNC server

You need to create a password to connect to the VNC server, to do this, run this command:



vncpasswd


Come up with a strong password, minimum length —  6 characters.

Next, we need to configure the ~/.vnc/xstartup file in order to enter the GUI when connecting via VNC

Run this command to open the ~/.vnc/xstartup file:



nano ~/.vnc/xstartup


Then paste this into it:



#!/bin/bash
# Start Gnome 3 Desktop

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

# Set the X session type and GDK backend to X11.
export XDG_SESSION_TYPE=x11
export GDK_BACKEND=x11

[-x /etc/vnc/xstartup] && exec /etc/vnc/xstartup
[-r $HOME/.Xresources] && xrdb $HOME/.Xresources

# Enable access control for X server
xhost +

# Start the Gnome session.
exec gnome-session


After that, be sure to give this file executable rights:



chmod +x ~/.vnc/xstartup


Now we are almost done!

All we have to do is start the VNC server and connect to it.

We will connect via ssh with port-forwarding using this command:



# Replace `okineadev@rpi.local` with the 
# username and address of your Raspberry Pi

ssh -L 5901:localhost:5901 okineadev@rpi.local


This command will connect you to the Raspberry Pi as usual, but with port 5901 forwarded to your computer, this is necessary because TigerVNC itself is not secure and the connection can be intercepted by attackers, so we will connect via port-forwarding because ssh itself provides encryption and connection security

Now we can start the VNC server:



vncserver :1


Now we can connect using TigerVNC:

And voila — now we were able to connect to the Raspberry PI using VNC! 😄

If you notice any mistakes in my instructions — report it in the comments

If you liked this guide, don’t forget to give it a few 👏

👇


This content originally appeared on DEV Community and was authored by Okinea Dev


Print Share Comment Cite Upload Translate Updates
APA

Okinea Dev | Sciencx (2024-10-05T14:29:09+00:00) How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04. Retrieved from https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/

MLA
" » How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04." Okinea Dev | Sciencx - Saturday October 5, 2024, https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/
HARVARD
Okinea Dev | Sciencx Saturday October 5, 2024 » How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04., viewed ,<https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/>
VANCOUVER
Okinea Dev | Sciencx - » How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/
CHICAGO
" » How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04." Okinea Dev | Sciencx - Accessed . https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/
IEEE
" » How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04." Okinea Dev | Sciencx [Online]. Available: https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/. [Accessed: ]
rf:citation
» How to set up VNC on a headless Raspberry Pi with Ubuntu Server 24.04 | Okinea Dev | Sciencx | https://www.scien.cx/2024/10/05/how-to-set-up-vnc-on-a-headless-raspberry-pi-with-ubuntu-server-24-04/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.