Hello everyone,
there are many articles online about how to set up a remote connection to an existing Xorg session via x11vnc, but I couldn’t find anywhere how to disable the local monitor and input so that anyone sitting next to the remote computer cannot see what you are doing or press buttons in your session. Below is my method of making x11vnc behave more like connecting to Windows via RDP.
So, let's assume you already know how to use x11vnc; if not, you can Google it or read something like .
Given: we launch x11vnc, connect to it with a client, everything works, but the local console of the computer is also available for viewing and input.
We want: disable the local console (monitor + keyboard + mouse) so that nothing can be seen or entered.
Turning off monitors
The first thing that came to mind was simply to turn off the monitor via xrandr like this:
$ xrandr --output CRT1 --off but in doing so, the desktop environment (I have KDE) starts to think that the monitor is really disconnected and begins to move windows and panels, everything shifts and becomes sad.
There’s a more interesting way, which involves sending the monitor to sleep, you can do this like:
$ xset dpms force offbut it’s not completely smooth. The system wakes the monitor at the first event. A simple workaround is the following loop:
while :; do
xset dpms force off
sleep .5
doneI didn’t think any further — I was lazy, it serves its purpose — the monitors show nothing, even if buttons are pressed, the mouse is moved, etc.
UPD:
Thank you for another method of turning brightness to zero:
$ xrandr --output CRT1 --brightness 0Disabling input
To disable input, I used xinput. When run without parameters, it outputs 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)]Devices Virtual core… disabling is not possible — an error is thrown, but the others can be turned on and off; for example, you can go a minute without a mouse like this:
xinput disable 9; sleep 60; xinput enable 9Ready solution
For my case, I created a script that I run in the ssh session. It disables local input and starts the x11vnc server, and after the script completes, everything returns to normal. In total, I have three scripts, 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
doneActually, the main script (I have two monitors; I start one shared 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 x11vncThat's it. We SSH in, run vnc_server, while it's running, we have access via vnc and the local console is turned off.
Thank you for your attention; additions and improvements are welcome.
Source: habr.com
