Security Handbook/Bootloader security

From Gentoo Wiki
Jump to: navigation, search
Security Handbook
Pre-installation concerns
Bootloader security
Mounting partitions
User and group limitations
File permissions
TCP wrappers
Kernel security
Network security
Securing services
Chrooting and virtual servers
Intrusion detection
Staying up-to-date

Tightening security by protecting the bootloader with a password.

Password protecting the boot loader

GRUB legacy

GRUB legacy supports two different ways of adding password protection to the boot loader. The first uses plain text, while the latter uses md5+salt encryption.

FILE /boot/grub/grub.conf
timeout 5
password changeme

This will add the password changeme. If no password is entered at boot, GRUB will simply use the default boot setting.

When adding an md5 password, the password must be converted into crypt format, which is the same format used in /etc/shadow. For more information see man crypt. The encrypted password changeme, for example, could look like this: $1$T7/dgdIJ$dJM.n2wZ8RG.oEiIOwJUs.

The password can be encrypted directly at the GRUB shell:

root #/sbin/grub
GRUB version 0.92 (640K lower / 3072K upper memory)

   [ Minimal BASH-like line editing is supported. For the first word, TAB lists
     possible command completions. Anywhere else TAB lists the possible
     completions of a device/filename. ]
grub> md5crypt

Password: ********
(Typed changeme at the prompt)
Encrypted: $1$T7/dgdIJ$dJM.n2wZ8RG.oEiIOwJUs.

grub> quit

Cut and paste the password into the /boot/grub/grub.conf file:

FILE /boot/grub/grub.conf
timeout 5
password --md5 $1$T7/dgdIJ$dJM.n2wZ8RG.oEiIOwJUs.

The 5 seconds timeout becomes handy if the system is remote and should be able to reboot without any keyboard interaction. Learn more about GRUB passwords by executing info grub.


Password protecting GRUB2 is performed in a similar way to GRUB legacy (listed above). First, the grub2-mkpasswd-pbkdf2 user space tool must be used in order to generate a pbkdf2 hash for the password:

root #grub-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.abcdef...

Next create a few new GRUB users in the /etc/grub.d/40_custom file. One of the users should be the superuser, the other user can have permissions to only boot specific boot entries.

FILE /etc/grub.d/40_custom
set superusers="root"
password_pbkdf2 root
password_pbkdf2 larry grub.pbkdf2.sha512.10000.ccc

To make boot options unrestricted (any GRUB2 user can boot unrestricted entries) add --unrestricted to each menuentry line in the /etc/grub.d/10_linux configuration file. This will look something like the following:

FILE /etc/grub.d/10_linuxUnrestricted boot entry
echo "menuentry '$(echo "$title" | grub_quote)' --unrestricted ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"

To only let the superuser and a specific user (with a password) boot an entry, add the --users option to the menuentry lines. The user "larry" is used in the example below:

FILE /etc/grub.d/10_linuxSpecific user boot entry
echo "menuentry '$(echo "$title" | grub_quote)' --users larry ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"

Finally, be sure to regenerate the grub.cfg file using the grub2-mkconfig command:

root #grub-mkconfig -o /boot/grub/grub.cfg


LILO also supports two ways of handling passwords: global and per-image, both in clear text.

The global password is set at the top of the configuration file, and applies to every boot image:

FILE /etc/lilo.conf

The per-image password is set as below:

FILE /etc/lilo.conf

If the restricted option is not entered, it will prompt for a password every time.

In order to store the new information in lilo.conf, /sbin/lilo must be run.