How to Protect GRUB with Password in Linux?

GRand Unified Bootloader, commonly known as GRUB, is a default bootloader on Unix OS. One of the security threats in a Linux system is that anyone can log in to a single-user mode and change the system settings. So, to avoid this, we require GRUB to set password protection.

1. Login with the root user.

2. Execute the command given below - 

# grub-md5-crypt
password --md5 $1$b7MLm0$UHtg4Ro6v/JrkWk8yBLMK0

It will ask for a password and generate an md5 hash password.
Copy it to a safe location

3. Open the file /boot/grub/menu.lst or /boot/grub/grub.conf and add the saved md5 password we generated earlier.

# vi /boot/grub/grub.conf      

Important Note
Take the backup of your GRUB file so we can restore it if there is an issue.

4. Now, add the generated md5 password into grub.conf file as password –md5.

5. Save the file by pressing the esc key and type:wq to save and exit.

6. Reboot your server.

7. From now onwards, whenever you have to edit the grub menu, you will need to provide the password as per the image shown below –


Was this answer helpful?

« Back