How to set grub password?

How to set grub password

There are two way to set the grub password in Linux.

  • By using commands
  • By changing in the configuration file

Here we are going to use commands for setting up the password of grub but first of all let’s understand what is grub & grub2?

Grub:- Grub full form is Grand unified boot loader. It is a boot loader package from GNU project. GNU Operating System uses Grub as its boot loader and grub2 is the updated version of grub.

Setting up grub password using command.

[[email protected] ~]# grub2-setpassword 
Enter password:
Confirm password:
[[email protected] ~]#

This command will set the password for the grub and it will take the root as a user name by default. Also it will generate a file called user.cfg that contain the password in encrypted form. As a result we can see in image below.

If you want to remove the password from grub or boot loader so you can delete the file /boot/grub2/user.cfg. Because this file contain the encrypted password or it will set the grub password.

Now we have another way to do the same task by changing in configuration file.

So let’s start by changing in configuration file.

In this way we have to generate a password for the grub using the command grub2-mkpasswd-pbkdf2 & set the password what ever we have as a result copy that result which start from grub.pbkdf and paste it in the /boot/grub2/grub.cfg file as shown in figure below.

[[email protected] ~]# grub2-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.269D7478CCD3CC5167329021EF463098F4F64633F2A2626ED29C241AE2CA7BFA5104A55F28F4AC1B2A3FC9E3CA82E394215DE4C36FD44C9B4BDD81606BFAC5E1.4DCCDCC3DDF97BFAD543E7273762E7E874BF9E680BA15506967B8BC9E07B9877D251CA2A609BBD76D8DB38B5ADC2FDB5F8BE965DEDD9FE617B4D2DF57F9F66AF
[[email protected] ~]#

[[email protected] ~]# vim /boot/grub2/grub.cfg

Go to the line number 86 and after the ### BEGIN /etc/grub.d/10_linux ###
set superusers="root"
export superusers
password_pbkdf2 root grub.pbkdf2.sha512.10000.269D7478CCD3CC5167329021EF463098F4F64633F2A2626ED29C241AE2CA7BFA5104A55F28F4AC1B2A3FC9E3CA82E394215DE4C36FD44C9B4BDD81606BFAC5E1.4DCCDCC3DDF97BFAD543E7273762E7E874BF9E680BA15506967B8BC9E07B9877D251CA2A609BBD76D8DB38B5ADC2FDB5F8BE965DEDD9FE617B4D2DF57F9F66AF

Finally we have almost done save and exit from this file & reboot your system and check the password is set or not? This the way to protect your grub with password.

Categories: Linux

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: