Hello everyone,
there are many articles on the Internet on how to set up a remote connection to an existing Xorg session via x11vnc, but I have not found anywhere how to pin down the local monitor and input so that anyone who sits next to the remote computer does not watch what you are doing and do not pressed buttons in your session. Under the cut, my way of making x11vnc look 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
Given: we launch x11nvc, connect to it as a client, everything works, but the local console of the computer is also available for viewing and entering.
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 to simply cut off the monitor using xrandr like this:
$ xrandr --output CRT1 --off
but at the same time, the window environment (I have KDE) starts 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 it like this:
$ xset dpms force off
but here, too, not everything is smooth. 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 - I was too lazy, it fulfills its purpose - the monitors do not show anything, even if you press the buttons, move the mouse, etc.
UPD:
Thank you
$ xrandr --output CRT1 --brightness 0
We cut down the input
To disable input, I used xinput. When run 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)]
Devices Virtual core... you canβt turn it off - an error is generated, but the rest can be turned on and off, for example, like this you can stay for a minute without a mouse:
xinput disable 9; sleep 60; xinput enable 9
Ready-made solution
For my case, I made a script that I run in an ssh session. It mutes local input and brings up the x11vnc server, and when the script ends, everything returns as it was. As a result, we got 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
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. Login via ssh, run vnc_server, while he is alive, we have vnc access and a extinguished local console.
Thank you for your attention, additions and improvements are welcome.
Source: habr.com