0

I'm trying to implement X11VNC on Ubuntu 20.04 but it's been frustrating. I need to use command way, the goal is to keep it on a systemd service.

As I know Ubuntu is using Xorg for the moment. Running ps wwwwaux | grep auth I get this:

gdm 3530 0.0 2.4 211180 50128 tty1 Sl+ 10:41 0:01 /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/125/gdm/Xauthority -background none -noreset -keeptty -verbose 3

admin-r+ 4700 0.2 2.7 216112 55220 tty2 Sl+ 11:58 0:02 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3

So it should be correct to run the X11VNC server like this when user is not logged in (forget security pls):

x11vnc -xkb -noxrecord -noxfixes -noxdamage -forever -rfbport 11226 -auth /run/user/125/gdm/Xauthority -display :0

And like this when it's logged in:

x11vnc -xkb -noxrecord -noxfixes -noxdamage -forever -rfbport 11226 -auth /run/user/1000/gdm/Xauthority -display :0

Well, it works good on GDM, but not when the user is logged in.

  • Tried with root and user profile of course.
  • UUIDs checked of course.

Also tried with the directive GDM conf file WaylandEnable=false commented and without comment. When comment it, it works running this when the user is logged in:

x11vnc -xkb -noxrecord -noxfixes -noxdamage -forever -rfbport 11226 -display :0

But not works in GDM. If I comment it, it works on GDM from root with:

x11vnc -xkb -noxrecord -noxfixes -noxdamage -forever -rfbport 11226 -auth /run/user/125/gdm/Xauthority -display :0

So I don't get a solution for everything. I'm now out of ideas. LightDM is not a solution, cause we want to use GDM3.

Any response will be highly appreciated.

Regards.

1

The problem was the display. As lightdm only uses one display (:0), GDM raises a display for each user, so this should be correct and works for me:

x11vnc -xkb -noxrecord -noxfixes -noxdamage -forever -rfbport 11226 -auth /run/user/1000/gdm/Xauthority -display :1

0

I've had similar problems. I couldn't login to Ubuntu on the boot screen. and finally came up with a workaround script to fix X11VNC's issues while using the default GDM3 on Ubuntu 21. I wish X11VNC would fix this.

Use this as a setup script to configure your X11VNC after installing x11vnc.

    #!/bin/bash


if [ -z "$1" ]; then echo "Please pass the password you would like to use as an argument to this script"; exit 1 ; else echo "Good start.going ahead."; fi

apt update && apt install tmux -y
password=$1
passwordfile='/etc/x11vnc.pass'
servicefile='/etc/systemd/system/x11vnc.service'
timerfile='/etc/systemd/system/x11vnc.timer'
script='/usr/bin/startxvnc'
apt-get update
apt-get install x11vnc net-tools -y
x11vnc -storepasswd $password $passwordfile



cat >$servicefile <<'EOT'
[Unit]
Description="x11vnc"
Requires=display-manager.service

[Service]
Type=simple
#Environment=XAUTHORITY=$(ps aux | grep -o -E "(-auth)(.*)(Xauth)[a-zA-Z]+")
#ExecStart=tmux new -s gj -d '/usr/bin/x11vnc $(ps aux | grep -o -E "(-auth)(.*)(Xauth)[a-zA-Z]+") -display :0 -rfbauth /etc/x11vnc.pass -shared -forever'
#ExecStartPre=tmux new -s x11vnc -d
ExecStart=bash -c /usr/bin/startxvnc
#ExecStop=tmux kill-session -t x11vnc
Restart=on-failure
RestartSec=2

[Install]
WantedBy=graphical.target
WantedBy=multi-user.target


EOT


cat >$timerfile <<'EOT'
Unit]
Description=Wait for some time before running X11VNC

[Timer]
OnBootSec=5sec

[Install]
WantedBy=timers.target

EOT




cat >$script <<'EOT'
#!/bin/bash

getxauths()
{
xauths=()

ps aux | grep -o -E "(-auth)(.*)(Xauth)[a-zA-Z]+" | (while IFS= read -r xauth
do
xauths+=("$xauth")
done
printf "%s\n" "${xauths[@]}" | sort -u
) }


getpname()
{
#psp=$(ps -p $(lsof -t -i:5900) -o command)
psp=$(cat /proc/$(lsof -t -i:$1)/cmdline)
echo $psp
}

killproc()
{
pkill -9 $(lsof -t -i:$1)
echo "Killed by port $1"
}


starttmux()
{
xauth=$1
        tmux new -s $xauth -d
        tmux send-keys -t $xauth:0 "for (( ; ; )) ; do sleep 3s; ((disp ^= 1)) ; /usr/bin/x11vnc -display :\$disp -auth $xauth -rfbauth /etc/x11vnc.pass -shared -forever ; done" Enter

}

#echo $(getpname)
start() {
for (( ; ; )) ; do

#echo $psp
xauths=$(getxauths)
for xauth in $xauths ; do
xauth="$xauth" | xargs
if [[ ${xauth} != *"-auth"* ]];then
            unset tsessions
            tsessions=($(tmux list-sessions -F '#{session_name}'))

echo "tessions is " ${tsessions[@]} 

echo "xauth is " ${xauth}
        if [[ ! " ${tsessions[@]} " =~ " ${xauth} " ]]; then
starttmux $xauth


psp=$(getpname 5900)
echo $psp | grep -E -o "(-auth)(.*)(Xauth)[a-zA-Z]+" | (while IFS= read -r xold
do
sessionname=$(echo ${xold#"-auth"} | xargs)
#tmux kill-session -t "$sessionname"
        if [[ ! " ${tsessions[@]} " =~ " ${xauth} " ]]; then
            if [[ $psp == *"user/125"*  ]] ; then killproc 5900 ; tmux kill-session -t "$sessionname"  ; echo "session name is $sessionname" ;
             fi ; else starttmux $xauth ; sleep 30s ; fi
done)

        fi

fi


done

sleep 3s
done
}
start
EOT

chmod u+x $script
sed -i -e 's/WaylandEnable=true/WaylandEnable=false/g' /etc/gdm3/custom.conf 
sed -i -e 's/#WaylandEnable=false/WaylandEnable=false/g' /etc/gdm3/custom.conf 

systemctl daemon-reload
systemctl enable x11vnc.timer
systemctl stop x11vnc.service
systemctl disable x11vnc.service
systemctl restart x11vnc.timer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.