This guide provides a complete walkthrough for setting up a Raspberry Pi running Ubuntu 24.04 for secure remote access from a Windows machine. We will configure a static IP address, install WireGuard for a secure VPN tunnel, and use x11vnc to access the Raspberry Pi’s graphical desktop.
For any server, it’s crucial to have a predictable IP address. A static IP ensures that your port forwarding rules and other network configurations will always work, as the Pi’s local address won’t change every time it reconnects to your network.
Using the Ubuntu Desktop GUI:
192.168.1.27 (This will be your Pi’s new, permanent local IP. You can choose a different one, but make sure it’s outside your router’s DHCP range).255.255.255.0 (This is standard for most home networks).192.168.1.1 (This is the IP address of your router. It might be different, like 192.168.0.1 or 10.0.0.1).8.8.8.8 and 1.1.1.1 (These are public DNS servers from Google and Cloudflare).hostname -I
The output should show 192.168.1.27.
WireGuard is a modern, fast, and secure VPN. We will use it to create a secure “tunnel” from your Windows PC to your Raspberry Pi, no matter where you are.
sudo apt update
sudo apt install wireguard
WireGuard uses a pair of cryptographic keys for security: a private key that stays on the server and a public key that you share with clients.
wg genkey | tee privatekey | wg pubkey > publickey
This command creates two files: privatekey (your server’s secret) and publickey (the one you’ll share).
cat command:
cat privatekey
cat publickey
This file defines the WireGuard VPN server settings on your Raspberry Pi.
sudo nano /etc/wireguard/wg0.conf
Paste the following configuration into the file. You must replace <PASTE YOUR SERVER PRIVATE KEY HERE> with the actual content of your privatekey file.
[Interface]
# This is the virtual IP address for your Raspberry Pi on the VPN network
Address = 10.8.0.1/24
# This is the port WireGuard will listen on for incoming connections
ListenPort = 51820
# Paste the contents of your 'privatekey' file here
PrivateKey = <PASTE YOUR SERVER PRIVATE KEY HERE>
# These commands enable IP forwarding, allowing VPN clients to access the internet through the Pi
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward
[Peer]
# This section is for your Windows client
# You will need to generate a key pair on your Windows machine and paste its public key here
PublicKey = <PASTE YOUR CLIENT (Windows) PUBLIC KEY HERE>
# This assigns a virtual IP to your Windows client within the VPN
AllowedIPs = 10.8.0.2/32
These commands will start the WireGuard server and configure it to launch automatically every time your Raspberry Pi boots up.
# Enable the service to start on boot
sudo systemctl enable wg-quick@wg0
# Start the service immediately
sudo systemctl start wg-quick@wg0
# Check the status of your WireGuard interface
sudo wg
On your Windows PC, you’ll need the official WireGuard client.
Use the following configuration. You will need to generate a new key pair within the Windows client and use its public key in the server configuration (wg0.conf) from Step 4.
[Interface]
# This is the virtual IP for your Windows machine on the VPN
Address = 10.8.0.2/24
# The client automatically generates and fills in its private key
PrivateKey = <THIS WILL BE FILLED IN BY THE WINDOWS CLIENT>
DNS = 1.1.1.1
[Peer]
# This is the public key from your Raspberry Pi (the 'publickey' file)
PublicKey = <PASTE YOUR SERVER (Pi) PUBLIC KEY HERE>
# This tells the client to route all traffic for the VPN's subnet through the tunnel
AllowedIPs = 10.8.0.0/24
# This is your home's public IP address and the port you are forwarding
Endpoint = <YOUR HOME'S PUBLIC IP ADDRESS>:51820
# This helps keep the connection alive through firewalls
PersistentKeepalive = 25
This step is critical. It tells your home router to send incoming WireGuard traffic to your Raspberry Pi.
192.168.1.27 (the static IP of your Pi)x11vnc is a VNC server that lets you view the actual desktop of your Raspberry Pi, not a virtual one.
sudo apt install x11vnc
x11vnc -storepasswd
To ensure the VNC server starts on boot, we’ll create a system service for it.
whoami
Remember this for the next step.
sudo nano /etc/systemd/system/x11vnc.service
Paste the following text. IMPORTANT: Replace both instances of lomadlidar with your own username.
[Unit]
Description=Start x11vnc at startup
After=display-manager.service
[Service]
Type=simple
User=lomadlidar
ExecStart=/usr/bin/x11vnc -display :0 -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/lomadlidar/.vnc/passwd -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable x11vnc.service
sudo systemctl start x11vnc.service
ping 10.8.0.1
If you get replies, your VPN is working!
10.8.0.1:5900You should now see your Raspberry Pi’s desktop.
If you make changes to your configurations, you can use these commands to restart the services.
# Restart WireGuard
sudo wg-quick down wg0
sudo wg-quick up wg0
# Restart the VNC Server
sudo systemctl restart x11vnc.service