In Ubuntu Server, the keyboard-setup.service is an initialization script executed early in the boot process to configure the virtual console’s keyboard map. It ensures that if a user plugs a physical keyboard into the server chassis, non-standard keymaps (like Dvorak or specific European layouts) are recognized by the raw TTY interface before the full multi-user environment loads. However, the vast majority of Ubuntu Server deployments are purely headless—residing in remote data centers or running as cloud virtual machines—meaning they are accessed exclusively via SSH. In a purely headless environment, spending system resources configuring a physical keyboard layout that will never be used is an unnecessary inefficiency.
This guide explains how to completely disable the keyboard-setup service in Ubuntu Server to eliminate this redundant boot step.
Stop and Mask the Keyboard Setup Service
To ensure the systemd initialization sequence completely ignores the keyboard mapping script, we must disable the service and mask it so that it cannot be triggered as a dependency by any other console-related process.
- Log into your Ubuntu Server via SSH using an account with
sudoprivileges. - First, ensure the service is stopped (although it typically runs and exits during early boot):
sudo systemctl stop keyboard-setup.service - Next, disable the service to prevent it from loading during the normal boot sequence:
sudo systemctl disable keyboard-setup.service - To absolutely guarantee that the service is dead and cannot be invoked by the initramfs or other console managers, mask it entirely:
sudo systemctl mask keyboard-setup.service
Verify the Boot Optimization
By masking the service, you have effectively symlinked its unit file to /dev/null. The server will now skip the process of parsing layout files and applying custom keymaps to the physical TTY framebuffer, relying entirely on the kernel’s default US-ASCII map, which is irrelevant anyway for SSH connections.
To verify the lockdown is successful, run the following command to check the status of the daemon:
systemctl status keyboard-setup.service
The output will clearly state that the service is masked. You have successfully eliminated a redundant initialization step, slightly optimizing the boot process of your headless server.