OGOPSEC // Dispatch
GRUB Security: Password-Protecting the Bootloader
GRUB security addresses a narrow but real weakness: by default, anyone at the keyboard during boot can edit a menu entry or drop to the GRUB command line. From there they can append init=/bin/bash, boot into a single-user shell, and — on an unencrypted system — walk straight into root. A bootloader password closes that door. It is a small change with an outsized effect on physical-access security, and it belongs on any laptop or kiosk that strangers can touch.
Before you start, be clear about what this is and is not. A GRUB password protects the boot menu. It does not encrypt anything, and it does not help if the attacker simply boots their own USB stick or pulls the disk. It is one layer among several.
How GRUB authentication works
Modern GRUB 2 supports a superusers list and per-user password hashes. You define a superuser, give it a PBKDF2 password hash, and GRUB then requires that credential to edit entries or use the console. You can optionally require it to boot specific entries too. The mechanics differ slightly between distribution families, so follow the section that matches your system.
RHEL, AlmaLinux, Rocky, Fedora
These distributions ship a helper that does the work for you. Run it as root:
sudo grub2-setpassword
You will be prompted for a password. The tool writes a PBKDF2 hash to /boot/grub2/user.cfg and sets the superuser to root. On UEFI systems the config path may live under /boot/efi/EFI/<distro>/; the helper handles the correct location. By default this configuration requires the password to edit entries, while still allowing a normal unattended boot of the default entry — which is usually what you want on a server that must reboot on its own.
Verify the hash file exists and is readable only by root:
sudo ls -l /boot/grub2/user.cfg
Debian, Ubuntu, and derivatives
Here you generate the hash yourself and wire it into the GRUB scripts. First create a PBKDF2 hash:
grub-mkpasswd-pbkdf2
Copy the resulting grub.pbkdf2.sha512.... string. Then add a superuser definition to a custom script so it survives updates. Edit /etc/grub.d/40_custom and add:
set superusers="admin"
password_pbkdf2 admin grub.pbkdf2.sha512.10000.YOUR_HASH_HERE
Regenerate the configuration:
sudo update-grub
By default, adding a superuser makes every entry require authentication to boot. If you want the machine to still boot the default entry unattended while only protecting editing, add the --unrestricted flag to the menu entries via /etc/grub.d/10_linux (set CLASS to include --unrestricted), then re-run update-grub. Test this on a machine you can physically recover before deploying it remotely.
Test it before you trust it
Reboot and confirm the behavior you configured:
- Pressing
eto edit an entry should prompt for the username and password. - Pressing
cfor the GRUB console should prompt as well. - If you chose unrestricted booting, the default entry should still start on its own.
If you locked yourself out, boot from installation media, mount your root and /boot, and remove or correct the superuser lines, then regenerate the config.
What GRUB security protects — and what it doesn't
A bootloader password stops the single most common physical-access shortcut: editing the boot line to get an unauthenticated root shell. That is worth having. But be precise about the boundaries:
- It does not encrypt your disk. An attacker who pulls the drive or boots their own media reads your files directly unless the filesystem is encrypted.
- It does not survive a firmware reset or, on some systems, a CMOS clear that an attacker with the case open can perform.
- It is only as good as your BIOS/UEFI protections. If the firmware boot order can be changed without a password, the attacker reaches for a USB stick instead.
The honest conclusion: set a GRUB password, and also set a firmware password, enable Secure Boot, and encrypt your disk. GRUB security is a cheap, effective layer, but it earns its keep only as part of a stack — the bootloader lock and the disk encryption cover each other's blind spots.