x11vnc Setup

1. Install x11vnc

sudo apt update && sudo apt install -y x11vnc

2. Set a VNC Password

x11vnc -storepasswd

Saves the password in ~/.vnc/passwd.


3. Run x11vnc (after login only)

If you just want remote control after logging in:

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

4. Run x11vnc at Login Screen (before login)

a) Create systemd service

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

Paste:

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

[Service]
ExecStart=/usr/bin/x11vnc -auth /var/lib/lightdm/.Xauthority -display :0 \
  -usepw -forever -loop -noxdamage \
  -rfbauth /home/your_user/.vnc/passwd -rfbport 5900 -shared
Restart=always
User=root

[Install]
WantedBy=multi-user.target

!! Replace your_user with your actual username.


b) 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 range.

c) Enable + start service

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

Check status:

sudo systemctl status x11vnc

d) Start the VNC Server

  1. reboot to auto launch x11vnc VNC Server or
  2. Manual Launch x11vnc with the password file and other options. The -display option ensures it connects to your current X11 session.
x11vnc -usepw -display :0

5. Connect from Windows

  1. Install TigerVNC Viewer : https://tigervnc.org/

  2. Open the viewer, enter your Debian IP with port 5900:

    192.168.150.10:5900
    
  3. Enter the password you set with x11vnc -storepasswd

  4. Done (you should see the same screen, including login screen)


6. Secure the Connection (Optional, via SSH Tunnel)

If connecting over the internet:

  1. Open PuTTY on Windows.

  2. Go to Connection : SSH : Tunnels

  3. Connect to your Debian SSH server.

  4. In TigerVNC Viewer, connect to:

    localhost:5900
    

7. Uninstall / Remove x11vnc (if needed)

Stop and disable service:

sudo systemctl stop x11vnc
sudo systemctl disable x11vnc
sudo systemctl status x11vnc

Remove service file:

sudo rm /etc/systemd/system/x11vnc.service
sudo systemctl daemon-reload
sudo systemctl reset-failed

Remove package + cleanup:

sudo apt remove --purge -y x11vnc
sudo apt autoremove -y

Delete password + config:

rm -rf /home/your_user/.vnc/passwd
rmdir /home/your_user/.vnc

Summary