Linux

How to set GRUB2 password

How to set GRUB2 password procedure in Centos and RHEL machines has been explained step by step in this article.

GRUB stands for Grand Unified Bootloader. It is a bootloader that is going to load your bootable files and also responsible for booting your Operating System.

Sometimes you can lose root user password. In order to recover the root password, we have to break into emergency mode. As a responsible person we can break the password, but anyone can do this and destruction your system. To avoid this, we need an extra layer of protection. That protection can be done by setting the GRUB password.

Set GRUB2 password in RHEL/CENTOS

If you have a GRUB password at the time of booting, if someone tries to enter into your machine (or) break the root password they must give username and password, if not they are not allowed to boot the system into emergency mode.

If a grub password is assigned, we can find a file called user.cfg at /boot/grub2 location.

Step1: Let’s check to see if grub password is assigned or not.
How to set GRUB2 password
Grub2 location
                        user.cfg file not existing

 

As we see user.cfg is not existing. So, no grub password is not assigned.

 

Step2: To Set grub password use grub2-setpassword use following command.

Set grub password
                                 Set grub2 password.

 

Now check you can find a new file called user.cfg .It contains an encrypted password which you can set.

 

How to set GRUB2 password

                                  user.cfg file is existing.

 

Step 3: Recreate the GRUB2 Configuration file.

In order to apply those changes into your grub configuration file, need to run a command called grub2-mkconfig -o /boot/grub2/grub.cfg . Automatically grub will be updated.

 

groubconfig
                                   update grub config file

 

To check grub functionality, reboot the system and try to boot into emergency mode.

 

How to set GRUB2 password
                                  Select kernel and press e in your keyboard.

 

 

it will redirect to next screen looking for username and password. Here we have to give password which we kept for GRUB2.

Enter Username and Password
               Required GRUB2 credentials.

 

If you provide the password, you can be able to do reset root password.

How to set GRUB2 password
                                         You can reset the root password.

 

 Removing GRUB Password Protection:

In case you don’t want the password for grub2, remove it by using rm -f /boot/grub2/user.cfg.

 

remove password
                      remove password for GRUB2.

 

By using ls /boot/grub2 you can see user.cfg file is not existing.

Apply that change by using grub2-mkconfig -o /boot/grub2/grub.cfg

 

make changes in grub
                                run the command for updated info.

 

Same procedure for Centos/RHEL machines as well.

 

Conclusion:

Additionally, GRUB 2 allows the user to pass kernel arguments. GRUB can be password protected in this way.

Thanks for your time, leave a comment if you have any queries about How to set GRUB2 password in RHEL Machine.

In Previous article explained about NIC teaming concept in RHEL.

Next PostAdding Memory and CPU with PowerCLI Previous PostRHEL 7 to RHEL 8 upgrade

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *