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

79 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

  14. Hi,
    I am running 16.04 and this fails with output:

    31/12/2017 16:18:24 passing arg to libvncserver: -rfbauth
    31/12/2017 16:18:24 passing arg to libvncserver: /home/ante/.vnc/passwd
    31/12/2017 16:18:24 x11vnc version: 0.9.13 lastmod: 2011-08-10 pid: 1940
    31/12/2017 16:18:24 XOpenDisplay(“”) failed.
    31/12/2017 16:18:24 Trying again with XAUTHLOCALHOSTNAME=localhost …
    31/12/2017 16:18:24
    31/12/2017 16:18:24 *** XOpenDisplay failed. No -display or DISPLAY.
    31/12/2017 16:18:24 *** Trying “:0” in 4 seconds. Press Ctrl-C to abort.
    31/12/2017 16:18:24 *** 1 2 3 4
    No protocol specified
    31/12/2017 16:18:28 XOpenDisplay(“:0”) failed.
    31/12/2017 16:18:28 Trying again with XAUTHLOCALHOSTNAME=localhost …
    No protocol specified
    31/12/2017 16:18:28 XOpenDisplay(“:0”) failed.
    31/12/2017 16:18:28 Trying again with unset XAUTHLOCALHOSTNAME …
    No protocol specified
    31/12/2017 16:18:28

    31/12/2017 16:18:28 ***************************************
    31/12/2017 16:18:28 *** XOpenDisplay failed (:0)

    *** x11vnc was unable to open the X DISPLAY: “:0”, it cannot continue.
    *** There may be “Xlib:” error messages above with details about the failure.

    Can you help ? Thanks Ante

  15. @Ante,

    Can you explain a little bit more your config ? are you working with an Headless configuration ? if this is the case, you might need to perform some additional configuration changes ?

    Hope this help
    Till next time
    See ya

  16. Hi Griffon,
    What is headless configuration?
    Everything works fine when I enter command x11vnc in the terminal. But I can’t have it at startup (before I am logged in).
    Thanks for your help

  17. @Ante;

    Note that the configuration described in the post works only for Ubuntu 16.04 and changes have been introduced in newer version of Ubuntu… so please confirm you are using the proper OS version…

    a headless configuration is when you have no monitor connected to the machine you want to connect to….
    Can you provide us the command you are typing in the terminal when the command is working ?
    If you have used the script; can you ensure that the file /etc/x11vnc.pass exists and contains the password you have specified
    Reboot your system, log into it and check the status of the x11vnc service (using sudo systemctl status x11vnc). Is the service running ?

    If all these conditions are met, you should be able to login to your Ubuntu machine….

    Hope this help
    Till next time
    See ya

  18. Hi,
    I reinstalled Ubuntu 16.04 LTS and executed the script on the fresh installation.Everything worked fine. Obviously problem was in the interfering some of the earlier installed applications.
    Thanks again.

  19. A few things could be improved in this script:

    – some config options could be asked interactively, eg. what port to run the server under.
    – you have to run this script as root, it should interactively ask for sudo permissions instead
    – the VNC server will run as root because the script is run as root, which I’m sure is not what most people would want. To fix this, specify the directive User=cnergy in the systemd service (or whatever your username is)

    aside from that, thanks for the script ! it did help me

  20. @Pepijn,

    Thank you for the visit and the feedback… We happy to see that this post was somewhat helpful to you
    Till next time
    See ya

  21. Hi there!
    I am facing the follow problem to enable the service in Ubuntu 16.04.3 LTS:

    Failed to start x11vnc.service: Unit x11vnc.service is not loaded properly: Invalid argument.
    See system logs and ‘systemctl status x11vnc.service’ for details.

    And the result of “systemctl status x11vnc.service” is:

    * x11vnc.service – Start x11vnc at startup.
    Loaded: error (Reason: Invalid argument)
    Active: inactive (dead)

    Could you help me?
    Thanks!

  22. @Alexander,

    Invalid argument might indicate that there is an error in the command line used in the unit file… or that you are missing the x11vnc.pass file…
    Can you try to execute the command manually on your machine and see if the command line is correct
    Then, can you try to locate the error more precisly through logs files or using the journalctl and the systemctl status command which should provide some hints about the error
    Waiting for your feedback
    Till next time
    See ya

  23. @KZ,

    thank you for the visit and positive feedback…Yes, this technique is still working on Ubuntu 16.04….:-)
    Till next time
    See ya

  24. Hi. Thanks for nice write-up. As mentioned above “Note that the configuration described in the post works only for Ubuntu 16.04 and changes have been introduced in newer version of Ubuntu… so please confirm you are using the proper OS version…” Have anybody tried it in Ubuntu 18.04? I look forward to trying it in the next few weeks. Cheers!

  25. @Drex_C,

    We had published a post about Ubuntu Gnome 17.04 to have VNC boot at startup but because of the change to GDM login page, it’s really become difficult to implement such solution..An alternative would be to use xRDP software solution that allows you to perform remote desktop connections. xRDP has the advantage that a new display is used and nobody can see what you are doing if in front of the screen of the remote machine. On the other hand, if you really need to Display 0, it’s not possible with xRDP and you would need to use vnc software solution ….

    in a few weeks, we will post something about VNC and Ubuntu 18.04, if you can wait till there…this might be a acceptable solution for you
    Till next time
    See ya

Leave a Reply