How to Set a Password for the GRUB Menu
Follow these steps to secure your GRUB bootloader with a password:
Step 1: Generate a Password Hash
Open a terminal and run the following command to generate a hashed password:
grub-mkpasswd-pbkdf2
Enter your desired password when prompted. The output will look like this:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.
Copy the entire hash for the next step.
Step 2: Edit the GRUB Configuration File
Open the GRUB configuration file for editing:
sudo vim /etc/grub.d/40_custom
Add the following lines to the file:
set superusers="admin"
password_pbkdf2 admin grub.pbkdf2.sha512.10000.
Replace admin with your desired username and paste the hash you generated earlier.
Step 3: Update GRUB
Run the following command to apply the changes:
sudo update-gruborsudo grub-mkconfig -o /boot/grub/grub.cfg
Step 4: Test the Password
Reboot your system and press Shift or Esc during boot to access the GRUB menu. Try editing a boot entry or accessing the GRUB command line. You should be prompted for the username and password.