Ubuntu 16.04 – Configure your system to have x11vnc running at startup

x11Vnc_u16_logo

Hello World;

Today, we continue our journey into the next to come release of Ubuntu (i.e. Ubuntu 16.04) and remote desktop connections. In the previous posts, we have updated the procedure to perform a standard xrdp installation and the procedure to perform a custom xrdp installation. 

Another post that has been quite popular is the one about having the x11vnc service running at startup.  This post will provide an update of the existing post that target Ubuntu 15.04 (see Ubuntu 15.04 – Configure your system to have x11vnc running at startup). The installation process has not changed since Ubuntu 15.x.  The previous post ( Ubuntu 15.04 – Configure your system to have x11vnc running at startup) was explaining how to perform the installation step by step.

In this post, instead of repeating the same things, we have put together a quick and dirty script that can help you configuring your system with X11VNC service running at startup.

Why would you need to have the x11vnc service at startup ? Simply because we would like to be able to login from a vnc client to a remote system where no users are currently logged on or to be able to access the system remotely even if multiple reboot occurs.

So, let’s see how we can achieve this

The Script

Content of the Script

Important Note :

If you copy/paste the script, you might encounter some issues because font formatting might be not maintained during the copy/paste operation. Please ensure that format is  accurate before launching the script. At the end of the post, you can download the script…

Disclaimer : As usual, use this at your own risk !! 

# ##################################################################
# Script Name : vnc-startup.sh
# Description : Perform an automated install of X11Vnc
# Configure it to run at startup of the machine 
# Date : Feb 2016
# Written by : Griffon 
# Web Site :http://www.c-nergy.be - http://www.c-nergy.be/blog
# Version : 1.0
#
# Disclaimer : Script provided AS IS. Use it at your own risk....
#
# #################################################################
# Step 1 - Install X11VNC 
# ################################################################# 
sudo apt-get install x11vnc -y
# Step 2 - Specify Password to be used for VNC Connection 
# #################################################################
sudo x11vnc -storepasswd /etc/x11vnc.pass
# Step 3 - Create the Service Unit File
# #################################################################
cat > /lib/systemd/system/x11vnc.service << EOF
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
EOF
# Step 4 -Configure the Service 
# ################################################################
echo "Configure Services"
sudo systemctl enable x11vnc.service
sudo systemctl daemon-reload
sleep 10
# Step 5 - Restart System 
# ################################################################
sudo shutdown -r now

As you can see, the script is really not to difficult.  We first install the x11vnc package. Then, we configure a vnc password to protect the access to the remote machine.  The remaining steps are creating and configuring the x11vnc service to run at startup through the systemd implementation.  At the end of the script, we reboot the machine and it’s time to check if the configuration has been performed accordingly or not.

Execute the script

To execute the script, you will need to have your system connected to internet.  This is needed because you will download some additional packages from Ubuntu Repository.

To execute this script, you will need to either copy/paste the script content into a text file on your Ubuntu machine (and please check formatting) or you can download the script from here to your Ubuntu machine.  You will need to mark the script as executable before you will be able to run it.

We will use the command line approach to perform all the necessary actions before running the script.  So, you will open a Terminal console and you type the following command

chmod +x  <%path_of_File%>/vnc-startup.sh   (adapt the path accordingly to match your system configuration)

You are ready to proceed with the automated installation of x11vnc and have it configured to run at startup.  As mentioned before, we assume that you have internet connection and you will be able to download all the necessary packages needed (x11vnc) to perform this configuration.

When you are ready, go to the folder containing the vnc-startup.sh script and you can execute the script by issuing the following command in the command prompt.

sudo ./vnc-startup.sh   

We assume that you have downloaded or created the file in the your home folder under the Download folders.  If this is not the case, browse to the location and execute the script from there.

Wait for completion of the script.  The machine will reboot automatically when done.

After the reboot, you can test your configuration by trying to connect to your ubuntu machine via the vnc client while nobody is logged into the system.

Screencast – Script Demo

We are providing hereafter also a short video demonstrating how the script works and what should be the final results. So, sit back and relax 🙂

Download Script

 

For your convenience, we are providing a downloadable version of the script. You can find it here

 

Final Notes

We have confirmed and validated that with Ubuntu 16.04, we can still have the x11vnc service running at startup which allows us to connect remotely even if no user are logged on or if reboots occur.  This configuration would also allow you to connect to the Unity desktop through xrdp (kind of). Check this post for more information.

This is it for today. Time to move on and blog about new things...

till next time

See ya

66 thoughts on “Ubuntu 16.04 – Configure your system to have x11vnc running at startup

  1. @Griffon,
    I had an opportunity to try this on an Ubuntu 17.04 PC, and I’m glad to share that it worked perfectly.
    One thing that I also did was removing vino. Not sure if it a requirement, since x11vnc starts first, but I did just to be on the safe side.
    Thanks much for your posts.

  2. hmmm, seems simple enough, except as soon as I start with the very first instruction (IE type “chmod +x /vnc-startup.sh” in terminal window) I get told No such file or directory.

    Is this a file that supposedly already exists? It doesn’t appear to on my computer (did a full search for anything like vnc-startup) or are we creating it here? I tried different paths or no path at all, but it’s still the same.

  3. @Graham…

    Have you read the full article….. ?
    Have you downloaded the zip file that attached at the end of the post….?
    The vnc-startup.sh is the script described in the post. at the end of the post, there a downloadable version of the script

    till next time
    See ya

  4. Hello Griffon |

    Thanks a lot for your sharings, very helpfull.
    The proposed solution works juste great for Ubuntu 16.04 with Unity
    I’ve tried – without luck so far – to make it work for Ubuntu Gnome 16.04

    Any idea ?

    Cheers,
    Michel

  5. @Michel,

    We would need to test this procedure on Ubuntu gnome and check what might be blocking you… We will try to have a look at it quite quickly as Ubuntu gnome is become the de facto official distribution

    Till next time
    see ya

  6. Griffon,
    Just used your script on Ubuntu Mate 16.04.3 running on an Odroid XU4. The only way it could have been easier is if someone else did the typing on my keyboard for me. Thank you for a great solution!

    Larry

  7. Hello Griffon,

    I was wondering if the Gnome issue have been resolved on your side ?
    I am going to investigate again on this, maybe this is related to the way the service is started… (upstart ??)

    Best,
    Michel

  8. @Michel;

    We have performed some test for vnc startup and gnome and we have it working…We still need to write and publish the step by step guide..but we are limited in time at the moment….(working travelling and trying to sleep time to time 🙂 ) We might have something ready to be published in begin/mid october 2017
    So, Stay tuned
    till next time
    See ya

  9. @Griffon

    Please, if you can write the solution you’ve found in Gnome environment, I would be eternally grateful 😉
    Thanx in advance.

    David.

  10. @DavidFL,

    Yes, we are working on that but we have a lot of work at the moment…so we will try to publish it quite soon…
    Stay tuned
    till next time
    See ya

  11. Until then, I have kind of fixed my own issue by using user autologin and running vino at session startup.
    Not ideal, since vino runs only during a user session, not with gdm.

  12. Based in your script i made an ansible playbook
    Tested on Xubuntu 12.04 to 16.04


    – hosts: linux
    become: true
    become_method: sudo

    tasks:
    – name: remover vino
    apt:
    name: vino
    state: absent
    force: yes

    – name: remover light-locket
    apt:
    name: light-locker
    state: absent
    force: yes

    – name: instalar x11vnc
    apt:
    name: x11vnc
    state: present
    force: yes

    – name: instalar xvfb
    apt:
    name: xvfb
    state: present
    force: yes

    – name: instalar xscreensaver
    apt:
    name: xscreensaver
    state: present
    force: yes

    – name: copiar archivo de configuracion
    copy:
    src: ../fuente/x11vnc.conf.
    dest: /etc/init/x11vnc.conf
    backup: yes
    force: yes

    – name: copiar archivo de paswords
    copy:
    src: ../fuente/x11vnc.pass
    dest: /etc/x11vnc.pass
    backup: yes
    force: yes

    – name: copiar archivo de service para 16.04
    copy:
    src: ../fuente/x11vnc.service
    dest: /lib/systemd/system/x11vnc.service
    backup: yes
    force: yes

    – name: habilitar el servicio para 16.04
    systemd:
    name: x11vnc.service
    enabled: yes
    masked: no

    – name: recargar servicios para 16.04
    systemd: daemon_reload=yes.

  13. @Auto;

    Thank you for the visit, the feedback and your contribution… we do not use ansible software (yet) and this might be useful to others….
    Till next time
    see ya

Leave a Reply