Setup a Kiosk with Ubuntu and Chromium

February 26, 2017 by Pat - Comments - 6 min read

OBrien Labs Ubuntu Kiosk SetupRecently I’ve had the need to setup 2 kiosk stations to display an array of data on a digital signage screen which has no keyboard or mouse attached to it. The idea in this post is to explain how I did it. I installed Ubuntu with the Unity desktop, set some auto-login tasks and run Chromium in kiosk mode. Then using xdotool to cycle through the Chrome tabs at a set interval. Lastly, the unclutter package will remove the mouse cursor from the screen, giving a clean automated look.

I also show how I’ve set this up for a Raspberry Pi. It’s mostly the same, but a few things are different. Check it out if you have a Raspberry Pi that you want to automate a display with!

Here’s how I did it:

Install Ubuntu

The first thing I did was get Ubuntu 16.04 Desktop installed. This worked for me with Ubuntu 14.04 as well. Once you have that installed, and sudo apt-get update && sudo apt-get upgrade to the latest and greatest, then move onto the next step.

Create User Accounts

Create 2 users. One user is already created – the account you’re logged in as. For this we’ll assume the account name is obrienlabs. Create a second user named kiosk. This will become the auto-logged in user.

The other account will be used to manage the system and any kiosk changes remotely via SSH. If you SSH into this machine as the kiosk user, you’ll end up running duplicate scripts.

Add Users To sudoers

I chose to add the 2 users to the sudoers file so I wouldn’t get prompted for passwords all the time. Run visudo and at the bottom add

kiosk ALL=(ALL) NOPASSWD: ALL
obrienlabs ALL=(ALL) NOPASSWD: ALL

Install Required Packages

We’ll need to install some software to accomplish this.

  • Chromium is the Chrome browser but with much more options.
  • Unclutter removes the mouse cursor from the screen, giving it a clean look.
  • xdotool can manipulate on screen elements using a virtual keyboard. We use it to change tabs in Chromium.

sudo apt-get install -y chromium-browser unclutter xdotool

Setup Auto Login

Now we can setup the auto login process. We need the user Kiosk to auto login on every reboot.

sudo nano /etc/lightdm/lightdm.conf and add:

[SeatDefaults]
autologin-user=kiosk
autologin-user-timeout=0
user-session=ubuntu
greeter-session=unity-greeter

Then run sudo mkdir /etc/lightdm/lightdm.conf.d && sudo nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf and add:

[SeatDefaults]
autologin-user=kiosk

Setup kiosk.sh Script

Now that we are auto logged in, let’s run our script.

Run sudo mkdir /home/kiosk/.config/autostart && sudo nano /home/kiosk/.config/autostart/kiosk.desktop and add:

[Desktop Entry]
Type=Application
Name=Kiosk
Exec=/home/kiosk/kiosk.sh
X-GNOME-Autostart-enabled=true

Installing the kiosk.sh script is as simple as copying the code below. This script will be launched every time the kiosk user logs in (even with SSH), so be sure to tailor it to your needs!

#!/bin/bash

# Run this script in display 0 - the monitor
export DISPLAY=:0

# Hide the mouse from the display
unclutter &

# If Chromium crashes (usually due to rebooting), clear the crash flag so we don't have the annoying warning bar
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/kiosk/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/kiosk/.config/chromium/Default/Preferences

# Run Chromium and open tabs
/usr/bin/chromium-browser --window-size=1920,1080 --kiosk --window-position=0,0 http://google.com http://bing.com &

# Start the kiosk loop. This keystroke changes the Chromium tab
# To have just anti-idle, use this line instead:
# xdotool keydown ctrl; xdotool keyup ctrl;
# Otherwise, the ctrl+Tab is designed to switch tabs in Chrome
# #
while (true)
  do
    xdotool keydown ctrl+Tab; xdotool keyup ctrl+Tab;
    sleep 15
done

Then make the script executable by running chmod +x kiosk.sh

As you can see Chromium runs in Kiosk mode. This means it’ll go full screen and take minimal input from the keyboard and mouse (if one was plugged in). In this example, Chromium will auto load Google and Bing in 2 tabs, and xdotool will cycle between the tabs every 15 seconds. I’m also performing some Chrome clean up in case the system reboots without closing Chrome. This will remove the nag bar.

Managing the system after it’s setup

To manage the system after it’s setup, you’ll need to find the IP of the device, and SSH into it using the OTHER USER you setup. Do not SSH in as user kiosk, or you’ll end up opening another Chromium instance, as well as kiosk.sh which will end up changing the tabs in more frequent intervals since xdotool will be called twice as fast.

Other things you can add to kiosk.sh are running x11vnc and autossh to automatically setup an SSH tunnel from the system to your centralized server, allowing you to SSH into the device and even VNC to the monitor without needing to know the IP. Very useful!

If you make any changes and want to log Kiosk out without rebooting, I’ve found that this command works. This will kill the kiosk.sh script and restart the Windows service which will log out and log in the kiosk user.

sudo killall kiosk.sh && sudo service lightdm restart

How to exit Kiosk mode

Ubuntu Unity UI allows you to press the Windows key on the keyboard to open the launcher. Once the launcher is open, type terminal. Once in the terminal type sudo killall chromium-browser or press Alt+F4 to close Chromium.

The kiosk.sh script will still be running, this script has the xdotool keydowns running (see above). We need to kill that too with sudo killall kiosk.sh. To remove it all together, refer to the above to remove the /home/kiosk/.config/autostart/kiosk.desktop file.

That’s basically it! A quick way to get a Kiosk setup which shows multiple tabs of information.

I hope this helps someone, and if you have any suggestions on improvements, let me know in the comments!

You can start your DigitalOcean Ubuntu server for as low as $5/mo and be online in 1 minute. Best yet, if you use this link you get $10 credit for free!

Share this post:

About Pat

I'm a I.T. systems engineer by day and in my spare time I code. I've made WordPress websites and plugins, weewx extensions and static html sites using Jekyll. I'm a technologist at heart and I enjoy tinkering on many different technology projects. Here on my site you will find some of the projects I've worked on, and other random bits of knowledge that I hope help someone along the way.

mentions