A Simple Guide for Setting Up Kiosk Mode in Ubuntu
Recently, I encountered a scenario where I needed to restrict user interaction to a single application on a system, ensuring that the user’s activity would be confined solely to that app. This kind of setup, commonly referred to as kiosk mode, is particularly useful in environments like public information kiosks, digital signage, or dedicated systems where limiting the user’s access is crucial.
In my case, I decided to configure kiosk mode on Ubuntu 22.04 LTS using GDM (GNOME Display Manager), which, for me, provided a more seamless experience compared to LightDM. While there are several ways to achieve kiosk mode, I found GDM to be a solid choice due to its robust handling of user sessions and ease of configuration.
This blog post is a step-by-step guide to configuring kiosk mode, which forces the system to launch directly into a single application with minimal distractions for the user. Whether you’re setting up a digital kiosk or simply looking to lock down user interaction on a machine, this guide should help you get started quickly.
Before we dive in, here are some quick notes about my setup:
- I’m using Ubuntu 22.04 LTS, but these steps should work on similar versions as well.
- We’ll be using GDM for the display manager, but feel free to adapt this guide if you’re using LightDM or another display manager.
So without further ado, let’s get into it.
- Create kiosk user
$ sudo useradd -m kiosk # -m is to create the user home directory $ sudo passwd kiosk
- Install unclutter (to hide mouse cursor), and Chromium browser (to view our HTML page)
$ sudo apt install unclutter $ sudo apt install chromium-browser
- Create a custom kiosk session
$ sudo nano /usr/share/xsessions/kiosk.desktop [Desktop Entry] Name=Ubuntu Kiosk Mode Comment=Kiosk Mode for Ubuntu Exec=/usr/local/bin/kiosk.sh Type=Application
- Create a custom kiosk shell script
$ sudo nano /usr/local/bin/kiosk.sh #!/bin/bash xset s off # Disable screensaver xset -dpms # Disable power management xset s noblank # Disable screen blanking unclutter -idle 0.01 -root # Hide mouse cursor
- Make it executable
$ sudo chmod +x /usr/local/bin/kiosk.sh
- Configure a user default session
$ sudo nano /var/lib/AccountsService/users/kiosk [User] XSession=kiosk Icon=/home/kiosk/.face SystemAccount=false [InputSource0] xkb=us
- Create a dummy HTML page for this blog post. In the actual case, we will be having a real webpage here instead.
$ sudo nano /home/kiosk/web/index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Kiosk Mode</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; font-family: Arial, sans-serif; } h1 { position: relative; font-size: 48px; transition: transform 0.3s ease-out; cursor: pointer; } </style> </head> <body> <h1 id="kiosk-text">Welcome to Kiosk Mode</h1> <script> const text = document.getElementById('kiosk-text'); text.addEventListener('mousemove', function(e) { const rect = text.getBoundingClientRect(); const x = e.clientX - rect.left - rect.width / 2; const y = e.clientY - rect.top - rect.height / 2; text.style.transform = `translate(${x * 0.5}px, ${y * 0.5}px)`; }); text.addEventListener('mouseleave', function() { text.style.transform = 'translate(0, 0)'; }); </script> </body> </html>
- We could invoke the Chromium browser directly from the shell script. Instead, let’s make a service and then let the service do the job for us.
$ sudo nano /etc/systemd/system/kiosk_chromium.service [Unit] Description=Service to Start Chromium in Kiosk Mode After=gdm.service [Service] User=kiosk Environment=DISPLAY=:0 ExecStart=/usr/bin/chromium-browser --kiosk --no-first-run --window-position=0,0 --window-size=1280,800 /home/kiosk/web/index.html Restart=always RestartSec=5 [Install] WantedBy=default.target
- Enable the service
$ sudo systemctl daemon-reload $ sudo systemctl start kiosk_chromium.service $ sudo systemctl enable kiosk_chromium.service
- Verify gdm3 is active
$ cat /etc/X11/default-display-manager /usr/sbin/gdm3
- Enable auto login. Look for
AutomaticLoginEnable
andAutomaticLogin
in/etc/gdm3/custom.conf
file. Make sure to uncomment both of them and assign correct username toAutomaticLogin
as shown below.$ sudo nano /etc/gdm3/custom.conf [daemon] AutomaticLoginEnable = true AutomaticLogin = kiosk
- Disable splash screen showing on boot
$ sudo nano /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT=""
- Update grub
$ sudo update-grub
- Reboot now
$ reboot
After reboot, you should see your webpage on Chromium browser.