Chapter 10. Protecting GRUB with a password
Chapter 10. Protecting GRUB with a password You can protect GRUB with a password in two ways: Password is required for modifying menu entries but not for booting existing menu entries. Password is required for modifying menu entries and for booting existing menu entries. 10.1. Setting password protection only for modifying menu entries You can configure GRUB to support password authentication for modifying GRUB menu entries. This procedure creates a /boot/grub2/user.cfg file that provides the password in the hash format. Important Setting a password using the grub2-setpassword command prevents menu entries from unauthorized modification but not from unauthorized booting. Procedure Issue the grub2-setpassword command as root: Enter the password for the user and press the Enter key to confirm the password: Note The root user is defined in the /boot/grub2/grub.cfg file with the password changes. Therefore, modifying a boot entry during booting requires the name and password of the root user. 10.2. Setting password protection for modifying and booting menu entries You can configure GRUB to prevent menu entries from unauthorized modification and booting. Warning If you forget the GRUB password, you will not be able to boot the entries you have reconfigured. Procedure Open the Boot Loader Specification ( BLS ) file for boot entry you want to modify from the /boot/loader/entries/ directory. Find the line beginning with grub_users . This parameter passes extra arguments to menuentry . Set the grub_users attribute to the user name that is allowed to boot the entry besides the superusers, by default this user is root . Here is a sample configuration file: + Save and close the BLS file: Note If you want to protect all the menu entries from booting, you can directly set the grub_users attribute. For example, if root is the user:
grub2-setpassword Enter password: Confirm the password: title Red Hat Enterprise Linux (4.18.0-221.el8.x86_64) 8.3 (Ootpa) version 4.18.0-221.el8.x86_64 linux /vmlinuz-4.18.0-221.el8.x86_64 initrd /initramfs-4.18.0-221.el8.x86_64.img USDtuned_initrd options USDkernelopts USDtuned_params id rhel-20200625210904-4.18.0-221.el8.x86_64 grub_users root grub_arg --unrestricted grub_class kernel grub2-editenv - set grub_users="root"