Disable the local console when using x11vnc

Hello,



On the Internet, there are many articles on how to configure a remote connection to an existing Xorg session via x11vnc, but I haven’t found anywhere how to pin down the local monitor and input so that anyone who sits next to the remote computer does not see what you are doing and not pressed buttons in your session. Under cat, my way to make x11vnc more like connecting to Windows via RDP.



So, let's say you already know how to use x11vnc, if not, you can google or read for example here .



Given: launch x11nvc, connect to it with the client, everything works, but the local computer console is also available for viewing and input.



We want: cut down the local console (monitor + keyboard + mouse) so that nothing can be seen and entered.



We cut down monitors



The first thing that came to mind was just to chop off the monitor via xrandr, for example like this:



$ xrandr --output CRT1 --off
      
      





but at the same time, the window environment (I have KDE) begins to think that the monitor is really turned off and starts throwing windows and panels, everything moves out and becomes sad.

There is a more interesting way, which is to send the monitor to sleep, you can do this for example like this:



 $ xset dpms force off
      
      





but here, too, not everything is going smoothly. The system wakes up the monitor at the first event. The simplest crutch in the form of a cycle helps:



 while : do xset dpms force off sleep .5 done
      
      





I didn’t think further - it was laziness, it fulfills its purpose - monitors do not show anything, even if you press buttons, wag the mouse, etc.

UPD:

Thanks amarao for another way to twist to zero brightness:

 $ xrandr --output CRT1 --brightness 0
      
      







Cut the input



To disable input, I used xinput. When launched without parameters, it displays a list of devices:



 $ xinput ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech USB Laser Mouse id=9 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ Power Button id=6 [slave keyboard (3)] ↳ Power Button id=7 [slave keyboard (3)] ↳ Sleep Button id=8 [slave keyboard (3)] ↳ USB 2.0 Camera: HD 720P Webcam id=10 [slave keyboard (3)] ↳ HID 041e:30d3 id=11 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=12 [slave keyboard (3)]
      
      





Virtual core devices ... cannot be disabled - an error is issued, but the rest can be turned on and off, for example, like this, you can remain without a mouse for a minute:



 xinput disable 9; sleep 60; xinput enable 9
      
      





Turnkey solution



For my case, I made a script that runs in ssh session. It suppresses local input and raises the x11vnc server, and upon completion of the script everything returns as it was. As a result, three scripts turned out, here they are (updated).



switch_local_console:



 #!/bin/sh case $1 in 1|on) desired=1 ;; 0|off) desired=0 ;; *) echo "USAGE: $0 0|1|on|off" exit 1 ;; esac keyboards=`xinput | grep -v "XTEST" | grep "slave keyboard" | sed -re 's/^.*\sid=([0-9]+)\s.*$/\1/'` mouses=`xinput | grep -v "XTEST" | grep "slave pointer" | sed -re 's/^.*\sid=([0-9]+)\s.*$/\1/'` monitors=`xrandr | grep " connected" | sed -re 's/^(.+) connected.*$/\1/'` for device in $mouses do xinput --set-prop $device "Device Enabled" $desired done for device in $keyboards do xinput --set-prop $device "Device Enabled" $desired done for device in $monitors do xrandr --output $device --brightness $desired done
      
      







disable_local_console:

 #!/bin/sh trap "switch_local_console 1" EXIT while : do switch_local_console 0 sleep 1 done
      
      





Actually, the main script (I have two monitors, I raise one common server and one for each monitor).



vnc_server:



 #!/bin/bash [[ ":0" == "$DISPLAY" ]] && echo "Should be run under ssh session" && exit 1 export DISPLAY=:0 killall x11vnc rm -r /tmp/x11vnc mkdir -p /tmp/x11vnc/{5900,5901,5902} params="-fixscreen V=5 -forever -usepw -noxkb -noxdamage -repeat -nevershared" echo "Starting VNC servers" x11vnc -rfbport 5900 $params 2>&1 | tinylog -k 2 -r /tmp/x11vnc/5900 & x11vnc -rfbport 5901 $params -clip 1920x1080+0+0 2>&1 | tinylog -k 2 -r /tmp/x11vnc/5901 & x11vnc -rfbport 5902 $params -clip 1920x1080+1920+0 2>&1 | tinylog -k 2 -r /tmp/x11vnc/5902 & echo "Waiting VNC servers" while [ `ps afx | grep -c "x11vnc -rfbport"` -ne "4" ] do sleep .5 done echo "Disabling local console" disable_local_console echo "Killing VNC servers" killall x11vnc
      
      





Actually everything. We go by ssh, run vnc_server while it is alive, we have access via vnc and the local console is extinguished.



Thank you for your attention, additions and improvements are welcome.



All Articles