I have a server running Ubuntu 12.10 and need to be able to remote to this server without being logged-in.
I have found many solutions, but none seem to work with 12.10.
Can anyone give me step-by-step instructions on how to configure x11vnc to start as a service (prior to user login) so that when connecting with VNC I will be presented with a graphical login screen?
I'm new to Linux so please give as much detail as possible in your responses/comments.
Thanks
010 Answers
The above answers solve the problem, though a couple of amendments for versions of Ubuntu with systemd (15.04+), as follows:
- Take advantage of new
-auth guessfunctionality in x11vnc - which helps! - Update for systemd (not upstart)
Run the following to install:
sudo apt-get install x11vnc
sudo x11vnc -storepasswd yourVNCpasswordHERE /etc/x11vnc.pass
# for Ubuntu 15.04+
sudo nano /lib/systemd/system/x11vnc.service
# for Ubuntu 16.10+
sudo nano /etc/systemd/system/x11vnc.serviceInsert this into the file:
[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service
[Service]
ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure
Restart-sec=2
[Install]
WantedBy=multi-user.targetThen, start with:
sudo systemctl daemon-reload
sudo systemctl start x11vncAnd ensure the service starts on boot:
sudo systemctl enable x11vnc 10 Install x11vnc:
sudo apt-get install x11vncCreate a password for your user:
x11vnc -storepasswdIf you have ssh setup you can use it to start x11vnc assuming you are logged in already, but remember to tell it to use your password file:
x11vnc -usepwIf you are not logged in you will get an error with the explanation:
If NO ONE is logged into an X session yet, but there is a greeter login
program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
to find and use the raw display manager MIT-MAGIC-COOKIE file.
Some examples for various display managers: gdm: -auth /var/gdm/:0.Xauth -auth /var/lib/gdm/:0.Xauth kdm: -auth /var/lib/kdm/A:0-crWk72 -auth /var/run/xauth/A:0-crWk72 xdm: -auth /var/lib/xdm/authdir/authfiles/A:0-XQvaJk dtlogin: -auth /var/dt/A:0-UgaaXaAssuming you are using lightdm for the login you can fix this problem you can start x11vnc with the command:
sudo x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepwI am not sure this is the best idea to run x11vnc as root. Maybe someone could edit with a way to access the login without using sudo.
Once this is running you should be able to connect using a vnc client such as krdc (for KDE). You might want to use GNU Screen to keep x11vnc running without needing the ssh session open
I was able to figure this out using .
Here is a sample upstart job you can use to make it run at startup. It needs to be put in /etc/init/x11vnc.conf. (Note that newer versions of Ubuntu use systemd so see the other answer that has a sample systemd config):
# description "start and stop x11vnc"
description "x11vnc"
start on runlevel [2345]
stop on runlevel [^2345]
console log
#chdir /home/
#setuid 1000
#setgid 1000
respawn
respawn limit 20 5
exec x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepwOnce you have made this file you can start it by running: sudo start x11vnc You can check the log at: /var/log/upstart/x11vnc.log
9Here's how:
Install the X11VNC server (or through Ubuntu Software Center -> X11VNC Server)
sudo apt-get install x11vncCreate a VNC password file.
sudo x11vnc -storepasswd yourVNCpasswordHERE /etc/x11vnc.passCreate a job file in the editor nano (or gedit, leafpad etc.).
sudo nano /etc/init/x11vnc.confPaste this into the file:
start on login-session-start script /usr/bin/x11vnc -xkb -forever -auth /var/run/lightdm/root/:0 -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -bg -o /var/log/x11vnc.log end scriptSave the file. You created a job for the Upstart event login-session-start.
- Restart Ubuntu.
That's it! You should now be able to connect with any VNC client even before login.
3babelmonks answer as a bash script, copy and save as x11vnc.sh & run with sudo bash /path/to/file/x11vnc.sh (sorry dont have enough rep to post a comment)
#!/bin/bash
#install x11vnc & set password
apt-get install x11vnc -y
x11vnc -storepasswd 123456 /etc/x11vnc.pass
#create config file for system service
cat > /lib/systemd/system/x11vnc.service <<-EOF
[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service
[Service] ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
ExecStop=/usr/bin/killall x11vnc
[Install]
WantedBy=multi-user.target
EOF
#restart new services & enable on boot
systemctl daemon-reload
systemctl start x11vnc
systemctl enable x11vnc 2 Here is a config works for sddm (for KDE 5). Currently, -auth guess does not work for sddm, the auth file is different every time, so we need something like -auth /var/run/sddm/*.
The service looks like,
[Unit]
Description="x11vnc"
After=multi-user.target
[Service]
ExecStart=/bin/sh -c "/usr/bin/x11vnc -xkb -noxrecord -display :0 -auth /var/run/sddm/* -rfbauth /etc/x11vnc.pass"
ExecStop=/usr/bin/killall x11vnc
[Install]
WantedBy=multi-user.targetI have to put it after multi-user.target, if after display-manager.service, x11vnc cannot find auth file, maybe sddm generates auth file later. This is tested on Manjaro 18.
Use my script for easy set up: installvncubuntu1604.sh
Usage:
chmod +x ./installvncubuntu1604.sh; sudo ./installvncubuntu1604.sh I use my own shell:
start on login-session-start
script
sudo /usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /var/srv/x11vnc/x11vnc.pass -forever -bg -rfbport <your_port> -o /var/srv/x11vnc/x11vnc.log
end scriptinto the file:
/etc/init/x11vnc.confIt makes it auto-start on boot, even on the logon screen it asks for a password.
Install x11vnc package
#sudo apt-get install x11vncThen set the password
#x11vnc -usepwThen create startup script for x11vnc
#sudo nano /etc/x11vnc.shIn File:
/usr/bin/x11vnc -bg -forever -shared -reopen -usepwThen save
#sudo chmod 777 /etc/x11vnc.shThen add the script file to Control Center=>Startup Application Then Click Add
> Name-----------x11vnc> Command-----<map the script file
> Comment------serviceThis is must be required to add for all user
This will run after user login only
If you are working with Ubuntu 19.04, you can check it out with my answer as I figured it out.
babelmonk's answer almost solves my problem. But I got a problem with display manager ( to deal with login page). I'm using Ubuntu 19.04 in which gdm3 is used. And yet, even with 'smart' -guess parameter from x11vnc, I couldn't connect to my Ubuntu. Thus, I changed it to lightdm which works well.
You can change your display manager in this command:
sudo dpkg-reconfigure gdm3BTW, if you wanna full steps to configure x11vnc, I wrote a full instruction.
An alternative to changing your display manager to fix this in Ubuntu 20 desktop or Ubuntu 21 Desktop is this script as a work around. On the default Ubuntu desktop installation, X11VNC does not work before logging in. This script automatically switches the Xauthority to use when logged in and when on the login screen even while using GDM3 as your display manager.
Plus, this one also auto configures X11VNC for you assuming that it's already installed.
It also runs X11VNC via tmux so you can see what is the issue after logging in incase you face issues.
#!/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]+")
#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 4