### VNC Viewer Connection Examples Source: https://github.com/libvnc/x11vnc/blob/master/README.md These examples show how to connect to a VNC server using the 'vncviewer' command, specifying the IP address or hostname and the display number or port. It covers connecting to a specific display number and how to connect when a non-standard port is used on the firewall. ```bash # Connect to display 0 on the machine with IP 24.56.78.93 vncviewer 24.56.78.93:0 # Connect to a VNC server listening on port 5944 (displayed as :44) vncviewer 24.56.78.93:44 ``` -------------------------------- ### Retrieve and Execute x11vnc for X-based Installations Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Commands to download a statically linked x11vnc binary, set execution permissions, and launch it for an X-based installation session. ```bash cd /tmp wget http://192.168.0.22/x11vnc.static chmod 755 ./x11vnc.static ./x11vnc.static -forever -nopw -display :0 -auth /tmp/wherever/the/authfile ``` -------------------------------- ### Start Virtual Display with Xorg Dummy Driver Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This command starts the X server using the 'dummy' Device Driver, configured via a specified xorg.conf file. This method creates a virtual framebuffer in main memory, similar to Xvfb, but with closer integration to the Xorg server. ```bash startx -- :1 -config /etc/X11/xorg.conf.dummy ``` -------------------------------- ### Start Virtual Display with Xdummy Wrapper Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This command uses the Xdummy script as an LD_PRELOAD wrapper to start the X server with the 'dummy' driver. This approach allows using a stock Xorg or XFree86 server without VT switching issues and supports dynamic screen resizing (RANDR). ```bash startx -- /path/to/Xdummy :1 ``` -------------------------------- ### Start x11vnc with SSL Source: https://github.com/libvnc/x11vnc/blob/master/doc/SSL.md Instructions for launching the x11vnc server using a previously generated SSL certificate. ```bash x11vnc -ssl SAVE -display :0 ``` -------------------------------- ### Configure local VNC session startup Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Shell script examples for .xinitrc to launch a virtual X display and connect a VNC viewer locally. ```bash #!/bin/sh x11vnc -create -rfbport 5905 -env WAITBG=1 vncviewer -geometry +0+0 -encodings raw -passwd $HOME/.vnc/passwd localhost:5 ``` ```bash #!/bin/sh x11vnc -create -rfbport 5905 -env WAITBG=1 vncviewer -FullScreen -PreferredEncoding raw -passwd $HOME/.vnc/passwd localhost:5 ``` -------------------------------- ### Example: accept_or_lock script Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md A practical example of a shell script that uses xmessage to prompt for client acceptance and locks the screen if the prompt times out, ensuring remote access is still possible. ```APIDOC ## Example: accept_or_lock script ### Description This shell script provides an example of how to use `xmessage` for interactive client acceptance with a timeout. If the timeout occurs, it locks the screen and accepts the client, allowing for unattended remote access. ### Method Shell Script (to be used with `-accept`) ### Endpoint N/A ### Parameters #### Script Arguments (via Environment Variables) - **RFB_CLIENT_IP** (string) - The IP address of the incoming client (used in the prompt). ### Request Example ```bash x11vnc ... -forever -accept 'yes:0,no:*,view:4 accept_or_lock' ``` ### Script Content: ```bash #!/bin/sh # # accept_or_lock: prompt user at X display whether to accept an incoming # VNC connection. If timeout expires, screen is locked # and the VNC viewer is accepted (allows remote access # when no one is sitting at the display.) # # usage: x11vnc ... -forever -accept 'yes:0,no:*,view:4 accept_or_lock' # xmessage -buttons yes:2,no:3,view-only:4 -center \ -timeout 60 "x11vnc: accept connection from $RFB_CLIENT_IP?" rc=$? if [ $rc = 0 ]; then xlock & # or "xlock -mode blank" for no animations. sleep 5 exit 0 elif [ $rc = 2 ]; then exit 0 elif [ $rc = 4 ]; then exit 4 fi exit 1 ``` ### Response #### Script Exit Codes: - **0**: Client accepted. - **2**: Client accepted (from xmessage button mapping). - **3**: Client rejected (from xmessage button mapping). - **4**: Client accepted view-only (from xmessage button mapping). - **1**: Client rejected (default or other unhandled cases). ``` -------------------------------- ### Unix stunnel 3.x Client Example Source: https://github.com/libvnc/x11vnc/blob/master/doc/OPTIONS.md This example demonstrates setting up an SSL tunnel on the viewer side using stunnel 3.x on Unix. It forwards local connections to a remote VNC server and then connects the VNC viewer to the local forwarded port. ```bash # stunnel client configuration on Unix stunnel -c -d localhost:5901 -r remotehost:5900 vncviewer localhost:1 ``` -------------------------------- ### Access control with hosts.allow Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This example demonstrates how to restrict access to the x11vnc service configured via inetd by specifying allowed IP addresses in the /etc/hosts.allow file. ```text # /etc/hosts.allow entry for x11vnc_sh x11vnc_sh : 123.45.67.89 ``` -------------------------------- ### Creating a Shell Script for x11vnc Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Provides a shell script example to automate the execution of x11vnc with common command-line options, allowing for easier startup and customization. ```bash #!/bin/sh # # filename: X11vnc (i.e. not "x11vnc") # It resides in a directory in $PATH. "chmod 755 X11vnc" has been run on it. # x11vnc -wait 50 -localhost -rfbauth $HOME/.vnc/passwd -display :0 $* ``` -------------------------------- ### Start x11vnc Server Source: https://github.com/libvnc/x11vnc/blob/master/doc/SSL-PORTAL.md Command to launch the x11vnc server with SSL enabled, requiring a password, and listening on a specific RFB port. ```bash x11vnc -ssl SAVE -http -display :0 -forever -rfbauth ~/.vnc/passwd -rfbport 5915 ``` -------------------------------- ### Custom Display Finding Script Example Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This is an example of a custom script that can be used with the '-display WAIT:cmd=' option in x11vnc. The script should output the DISPLAY environment variable on the first line and optionally XAUTHORITY information or raw xauth data on subsequent lines. This allows x11vnc to dynamically determine the X display to attach to. ```bash #!/bin/sh # Example script to find X display and XAUTHORITY # Find the user's X display (replace with actual logic) DISPLAY=:0 # Find the XAUTHORITY file (replace with actual logic) XAUTHORITY=/home/user/.Xauthority echo "DISPLAY=${DISPLAY}" # Optionally output XAUTHORITY data # echo "XAUTHORITY=${XAUTHORITY}" # Or output raw xauth data # xauth list ``` -------------------------------- ### Basic x11vnc and vncviewer Setup in .xinitrc Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This script configures x11vnc to run on a specific display and port, and then launches a vncviewer to connect to it. It's designed for minimal X server setups without a window manager, where the VNC viewer displays the virtual X session on the real X server. Ensure display numbers and ports match your configuration. ```shell #!/bin/sh x11vnc -display :5 -rfbport 5905 -bg vncviewer -geometry +0+0 -encodings raw -passwd $HOME/.vnc/passwd localhost:5 ``` ```shell #!/bin/sh x11vnc -display :5 -rfbport 5905 -bg vncviewer -FullScreen -PreferredEncoding raw -passwd $HOME/.vnc/passwd localhost:5 ``` -------------------------------- ### Configure with Specific Library Prefix Source: https://github.com/libvnc/x11vnc/blob/master/README.md Configures the x11vnc build, specifying a custom installation prefix for libraries like libjpeg, and then proceeds with the compilation. ```bash env PATH=/usr/local/bin:/usr/ccs/bin:$PATH sh -c './configure --with-jpeg=/usr/sfw; make' ``` -------------------------------- ### Access VNC via URL Parameters Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Demonstrates how to pass the PORT and GET parameters directly via the URL to the proxy.vnc file to override default settings. ```URL https://yourmachine.com/proxy.vnc?PORT=443 ``` ```URL https://yourmachine.com/proxy.vnc?GET=1&PORT=443 ``` -------------------------------- ### Start Xvfb with x11vnc for Efficient Polling Source: https://github.com/libvnc/x11vnc/blob/master/README.md This command shows how to start Xvfb as an X server and then use x11vnc to poll it. This method allows x11vnc to efficiently read screen data from main memory, which can be faster than directly reading the hardware framebuffer. The '-cc 4' option may be needed to force a TrueColor visual. ```bash xinit $HOME/.xinitrc -- /usr/X11R6/bin/Xvfb :1 -screen 0 1024x768x16 x11vnc -create -clip 0x0+1024+768 -rfbport 5900 :1 ``` -------------------------------- ### Configure Legacy Stunnel for x11vnc Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Examples of using the legacy -stunnel option to wrap VNC traffic. This requires the stunnel utility to be installed on the system and available in the PATH. ```bash x11vnc -display :0 -stunnel /path/to/stunnel.pem -passwdfile ~/mypass x11vnc -display :0 -stunnel SAVE ``` -------------------------------- ### Run VNC Viewer with Localhost Connection Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This command starts the VNC viewer, connecting to localhost on display 0. When used with the SSH tunnel setup, this connects the viewer to the remote VNC server. ```bash vncviewer -encodings "copyrect tight zrle hextile" localhost:0 ``` -------------------------------- ### x11vnc Password Authentication Setup and Usage Source: https://context7.com/libvnc/x11vnc/llms.txt Configures VNC password protection for secure remote connections. This involves creating a password file using x11vnc -storepasswd or a plain text file, and then starting x11vnc with the appropriate authentication option (-rfbauth or -passwdfile). Supports separate view-only passwords. ```bash # Create a VNC password file x11vnc -storepasswd your_password ~/.vnc/passwd # Start x11vnc with password authentication x11vnc -display :0 -rfbauth ~/.vnc/passwd # Alternative: use a text password file echo "mysecretpassword" > ~/.vnc/x11vnc.pass chmod 600 ~/.vnc/x11vnc.pass x11vnc -display :0 -passwdfile ~/.vnc/x11vnc.pass # Password file with view-only access (2nd line is view-only password) cat > ~/.vnc/passwords.txt << 'EOF' fullaccess_password __BEGIN_VIEWONLY__ viewonly_password EOF x11vnc -display :0 -passwdfile ~/.vnc/passwords.txt ``` -------------------------------- ### x11vnc inetd Configuration for Fixed User with VNC Password Authentication Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This example shows an inetd configuration for a specific user ('fred') that uses VNC password authentication (-rfbauth) instead of UNIX passwords. It switches to the specified user and finds their X display. SSL is not strictly required in this setup, but the UNIX password is not used for authentication. ```bash /usr/local/bin/x11vnc -inetd -users =fred -find -rfbauth /home/fred/.vnc/passwd -o /var/log/x11vnc.log ``` -------------------------------- ### Execute x11vnc for Console-Framebuffer Installations Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Commands to launch x11vnc in raw framebuffer mode for console-based installations, using a sleep delay to allow switching back to the installation console. ```bash sleep 10; ./x11vnc.static -forever -nopw -rawfb console ``` -------------------------------- ### x11vnc Reflector Setup (Command Line) Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Demonstrates the command-line usage of x11vnc to set up a VNC reflector. This involves specifying the target VNC server using the -reflect option and optionally configuring reverse connections. ```bash x11vnc -reflect listen -connect client1,client2,... ``` ```bash x11vnc -display :0 -connect repeater1,repeater2,... ``` -------------------------------- ### Install Build Dependencies (Debian) Source: https://github.com/libvnc/x11vnc/blob/master/README.md Installs the necessary development packages for building x11vnc on Debian-based systems using apt-get. ```bash sudo apt-get build-dep x11vnc ``` -------------------------------- ### x11vnc Command for Display Manager Scripts Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This is a general example of the x11vnc command to be added to display manager startup scripts. It includes options for authentication, logging, and persistent operation. Customize paths and options as needed. ```bash /usr/local/bin/x11vnc -rfbauth /path/to/the/vnc/passwd -o /var/log/x11vnc.log -forever -bg ``` -------------------------------- ### x11vnc Help and Version Information Source: https://github.com/libvnc/x11vnc/blob/master/doc/OPTIONS.md Display help text, list available options, or show program version and modification date. These options are standard for command-line utilities. ```bash -h, -help Print this help text. -?, -opts Only list the x11vnc options. -V, -version Print program version and last modification date. -license Print out license information. Same as -copying and -warranty. ``` -------------------------------- ### Configuring x11vnc with .x11vncrc File Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Illustrates how to use the $HOME/.x11vncrc configuration file to specify command-line options for x11vnc, simplifying its invocation. ```bash -wait 50 -localhost -rfbauth $HOME/.vnc/passwd -display :0 ``` -------------------------------- ### Install Ubuntu build dependencies for x11vnc Source: https://github.com/libvnc/x11vnc/blob/master/README.md This command installs the necessary packages required to compile x11vnc on Ubuntu Feisty Fawn (7.04). It includes essential build tools, libraries for JPEG and SSL, and X11 test support. ```bash apt-get install build-essential make bin86 libjpeg62-dev libssl-dev libxtst-dev ``` -------------------------------- ### Configure x11vnc with inetd Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This snippet shows how to configure x11vnc to run under inetd. It includes the necessary entry for /etc/inetd.conf and a sample shell script (/usr/local/bin/x11vnc_sh) to launch x11vnc with specific options like -inetd, -display, -auth, and logging. ```bash # /etc/inetd.conf entry 5900 stream tcp nowait root /usr/sbin/tcpd /usr/local/bin/x11vnc_sh # /usr/local/bin/x11vnc_sh script example #!/bin/sh /usr/local/bin/x11vnc -inetd -display :0 -auth /home/fred/.Xauthority \ -rfbauth /home/fred/.vnc/passwd -o /var/log/x11vnc_sh.log ``` -------------------------------- ### Start Xvfb Virtual Display Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This command starts an Xvfb virtual framebuffer X server. It creates a virtual display on screen 0 with a specific resolution and color depth. This virtual display can then be exported via VNC using x11vnc. ```bash xinit -- /usr/bin/Xvfb :1 -cc 4 -screen 0 1024x768x16 ``` -------------------------------- ### Start x11vnc in .xsession/.xinitrc Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This command is used within a user's .xsession or .xinitrc file to start x11vnc automatically when the user logs into their X session. It configures logging, authentication, and keeps the VNC server running indefinitely in the background. ```bash x11vnc -logfile $HOME/.x11vnc.log -rfbauth $HOME/.vnc/passwd -forever -bg ``` -------------------------------- ### Start x11vnc in Terminal on Mac OS X Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md This shell script is designed to be run on Mac OS X. It opens a Terminal window and executes the x11vnc command, which is useful for enabling clipboard exchange when x11vnc is started from within the Aqua display session. ```bash #!/bin/sh # # start_x11vnc: start x11vnc in a Terminal window ``` -------------------------------- ### Configure x11vnc with inetd Source: https://context7.com/libvnc/x11vnc/llms.txt Instructions for launching x11vnc on-demand using inetd or xinetd super-servers. ```bash # /etc/inetd.conf entry example: # 5900 stream tcp nowait root /usr/bin/x11vnc x11vnc -inetd -display :0 -auth guess -o /var/log/x11vnc.log # Or for xinetd (/etc/xinetd.d/x11vnc): # service x11vnc # { # type = UNLISTED # port = 5900 # socket_type = stream # protocol = tcp # wait = no # user = root # server = /usr/bin/x11vnc # server_args = -inetd -display :0 -auth guess -q -o /var/log/x11vnc.log # } # Important: always use -q with -inetd to prevent stderr going to viewer x11vnc -inetd -q -display :0 -auth guess ``` -------------------------------- ### DtLogin Configuration for x11vnc (Solaris) Source: https://github.com/libvnc/x11vnc/blob/master/doc/FAQ.md Instructions for setting up x11vnc with the DtLogin display manager on Solaris. This includes creating directories, copying configuration files, uncommenting 'Dtlogin*grabServer: False', and adding the x11vnc command to Xsetup. ```bash mkdir -p /etc/dt/config ``` ```bash cp /usr/dt/config/Xconfig /etc/dt/config/Xconfig ``` ```text Dtlogin*grabServer: False ``` ```bash cp /usr/dt/config/Xsetup /etc/dt/config/Xsetup ``` ```bash /usr/local/bin/x11vnc -forever -o /var/log/x11vnc.log -bg ``` ```bash /etc/init.d/dtlogin stop /etc/init.d/dtlogin start ``` -------------------------------- ### Start x11vnc with VNC Viewer and Password Prompt Source: https://github.com/libvnc/x11vnc/blob/master/README.md Initiates an x11vnc session and connects to it using vncviewer. The sleep command ensures services start before connection. Redirecting input to prompts the vncviewer to ask for the password via a popup window. Output is discarded. ```bash (sleep 10; vncviewer -encodings "copyrect tight zrle zlib hextile" \ localhost:0 /dev/null) & ```