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.
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.
Now check you can find a new file called user.cfg .It contains an encrypted password which you can set.
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.
To check grub functionality, reboot the system and try to boot into emergency mode.
it will redirect to next screen looking for username and password. Here we have to give password which we kept for GRUB2.
If you provide the password, you can be able to do reset 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.
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
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.