x11vnc Setup for Debian XFCE

1. Install x11vnc

sudo apt update && sudo apt install -y x11vnc

2. Set a VNC Password

x11vnc -storepasswd

This saves the password file at ~/.vnc/passwd initially.


3. Run x11vnc (after login only)

If remote control is only needed after user login:

x11vnc -auth guess -display :0 -usepw -forever

4. Run x11vnc at Login Screen (before login)

a) Move VNC Password File for system-wide access

Since systemd service runs as root:

sudo mkdir -p /etc/x11vnc
sudo mv /home/your_user/.vnc/passwd /etc/x11vnc/passwd
sudo chown root:root /etc/x11vnc/passwd
sudo chmod 600 /etc/x11vnc/passwd

Replace your_user with your actual username.


b) Create and edit systemd service

sudo nano /etc/systemd/system/x11vnc.service

Paste this content:

[Unit]
Description=Start x11vnc at login screen
After=display-manager.service
Wants=display-manager.service

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -display :0 \
  -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc/passwd \
  -rfbport 5900 -shared
Restart=on-failure
RestartSec=5
User=root

[Install]
WantedBy=multi-user.target

The key option here is -auth guess which dynamically finds the correct X authority file to avoid black screens after locking.


c) Enable and start systemd service

sudo systemctl daemon-reload
sudo systemctl enable x11vnc
sudo systemctl start x11vnc
sudo systemctl status x11vnc

d) Install and switch to xscreensaver for lock screen

To fix the black screen in VNC after locking:

sudo apt remove -y light-locker
sudo apt install -y xscreensaver xscreensaver-data

Enable xscreensaver autostart:

Or ensure the "Screen Saver" entry exists and is enabled.

Reboot:

sudo reboot

5. Configure Firewall (Optional, recommended)

sudo apt install -y ufw gufw
sudo ufw allow from 192.168.150.0/24 to any app VNC
sudo ufw enable
sudo ufw reload
sudo ufw status verbose

Replace 192.168.150.0/24 with your actual IP subnet.


6. Connect from Windows


7. Secure Connection Over Internet (Optional)

Use SSH tunneling for encryption:


8. Uninstall / Remove x11vnc (if needed)

sudo systemctl stop x11vnc
sudo systemctl disable x11vnc
sudo rm /etc/systemd/system/x11vnc.service
sudo systemctl daemon-reload
sudo systemctl reset-failed
sudo apt remove --purge -y x11vnc
sudo apt autoremove -y
sudo rm -f /etc/x11vnc/passwd
rm -rf /home/your_user/.vnc/passwd
rmdir /home/your_user/.vnc

Summary

This setup ensures a reliable, continuous remote desktop experience on Debian XFCE via x11vnc.