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

http://c-nergy.be/blog/?p=8984

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