GRUB (Grand Unified Bootloader) is the default boot loader in all Linux/UNIX systems. But it is not password protected, so anyone can access it and make changes to it, and damage your system boot. To prevent this scenario, it is necessary to secure GRUB with password. In this article, we will learn how to generate GRUB password in Linux to prevent unauthorized people from accessing it.
How to Generate GRUB Password in Linux
Here are the steps to generate, modify and remove GRUB password in Linux
Generate GRUB password
You can set GRUB password using the following command in terminal.
You will be prompted to enter GRUB password of your choice and enter it again to confirm it. So enter the password twice.
This will generate a hashed password at /boot/grub2/user.cfg and you can view it with the following command.
# cat /boot/grub2/user.cfg
Recreate GRUB Configuration File
After you create GRUB password, you need to recreate new GRUB configuration file using the following command.
# grub2-mkconfig -o /boot/grub2/grub.cfg
The above command will set the GRUB password in its configuration file. You will see the following message.
Generating grub configuration file... done
Next, reboot the system and check if you are prompted for GRUB password.
Test GRUB Password Protection
When you reboot your system, you will see the following screen for 5 seconds that allows you to avoid the usual boot sequence and enter GRUB settings. Press ‘e’ quickly to enter GRUB settings and break the regular boot process.
When you enter ‘e’ key, you will be prompted for GRUB password. Enter username as root and the password as what you set it to earlier.
On successful authentication, you will enter GRUB editor and be able to make changes to it.
Remove GRUB Password Protection
You can remove GRUB password protection by simply deleting /boot/grub2/user.cfg file.
# rm /boot/grub2/user.cfg
In this article, we have learnt how to generate, enable, test and remove GRUB password. Please note, it is not enough to generate GRUB password, but you need to recreate GRUB configuration file to enable it.
How to Restore Deleted Tmp Directory in Linux
How to Change Linux Partition Label Names
How to Disable Output Buffering in Python
How to Read Large Files in Python
How to Copy File Permissions & Ownership in Linux