How to Connect via VNC to an Existing X Session on Linux (x11vnc Alternative Methods)


2 views

When trying to remote into a Linux workstation, most traditional VNC servers create new X sessions rather than attaching to existing ones. This breaks workflow continuity - you lose access to all open applications and desktop state from your physical workstation.

The classic solution was x11vnc, which directly captures the current X11 framebuffer. However, as noted in the original question, some modern distros like Fedora no longer package it by default due to security concerns with raw X11 access.


# Old x11vnc command example (if available):
x11vnc -display :0 -forever -shared -rfbauth ~/.vnc/passwd

Method 1: Using TigerVNC's X0tigervnc

Most Fedora systems include TigerVNC, which can attach to existing sessions:


sudo dnf install tigervnc-server
X0tigervnc -geometry 1920x1080 -SecurityTypes=VncAuth -PasswordFile=/etc/vncpasswd

Method 2: GNOME Remote Desktop

For GNOME users on Wayland (Fedora's default):


gsettings set org.gnome.desktop.remote-desktop.vnc auth-method 'password'
gsettings set org.gnome.desktop.remote-desktop.vnc view-only false

For headless setups where no physical display exists, create a virtual X server first:


Xvfb :1 -screen 0 1920x1080x24 &
export DISPLAY=:1
startxfce4 &  # or your preferred DE
x0vncserver -PasswordFile=~/.vnc/passwd -Display :1

Even behind VPN, always:

  • Use at least 8-character VNC passwords
  • Consider SSH tunneling: ssh -L 5900:localhost:5900 user@workstation
  • Set firewall rules to restrict VNC port access

Common issues and fixes:

Error Solution
Cannot open display Verify with echo $DISPLAY
Blank screen Add -noxdamage flag to VNC server
Input not working Check -viewonly isn't set

When you need remote access to your physical workstation's existing X11 session (display :0), standard VNC solutions often create a new virtual session instead. Here's how to properly attach to the currently running desktop environment.


# Install on Debian/Ubuntu
sudo apt install x11vnc

# Install on RHEL/Fedora (EPEL required for older versions)
sudo dnf install x11vnc

# Basic usage (attach to display :0)
x11vnc -display :0 -forever -shared -noxdamage -passwd yourpassword

1. Using X Server's Built-in XDMCP


# Edit lightdm.conf (Ubuntu) or gdm.conf (RHEL)
[XDMCPServer]
enabled=true
port=177

# Connect via Xvnc
vncviewer -via user@host localhost:5900

2. Screen Scraping with vncserver


# Create virtual framebuffer
Xvfb :1 -screen 0 1920x1080x24 &

# Capture and forward display :0
x0vncserver -display :0 -passwordfile ~/.vnc/passwd

Even behind VPN, implement these precautions:

  • Always use -passwd option (never plain text passwords)
  • Consider SSH tunneling: ssh -L 5900:localhost:5900 user@host
  • Set up firewall rules to restrict VNC port access
Error Solution
Cannot open display ":0" Run as same user owning the X session or use xhost +
Black screen Add -noxdamage flag or try -rawfb option
Keyboard mapping issues Set -nomodtweak and -nomodkeycode

For production environments, create a systemd service:


# /etc/systemd/system/x11vnc.service
[Unit]
Description=X11VNC Server
After=display-manager.service

[Service]
ExecStart=/usr/bin/x11vnc -display :0 -forever -shared -passwdfile /etc/x11vnc.pass
Restart=always

[Install]
WantedBy=multi-user.target