• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 6 : How to password protect grub (Password-Protected Booting)

by admin

The GRUB bootloader stores the password in a plaintext file, so any encrypted form of the password is required. To generate an encrypted password we may use grub-crypt command. Until now we have used the command grub-md5-crypt. But now MD5 is widely-considered broken. grub-crypt uses SHA-256 or SHA-512 hashes, which are considered more secure. The general syntax/usage of the grub-crypt command is as shown below :

# grub-crypt --help
Usage: grub-crypt [OPTION]...
Encrypt a password.

  -h, --help              Print this message and exit
  -v, --version           Print the version information and exit
  --md5                   Use MD5 to encrypt the password
  --sha-256               Use SHA-256 to encrypt the password
  --sha-512               Use SHA-512 to encrypt the password (default)

Report bugs to [bug-grub@gnu.org].
EOF

Using SHA-265 or SHA-512 hashes

1. As the root user, use the grub-crypt command to generate password hash. Type the password and re-type password for confirmation.

grub-crypt
Password:
Retype password:
$6$GXGrYVEnbKXAnQoT$p64OkyclNDt4qM2q47GMsgNxJxQaclNs79gvYYsl4h07ReDtJpt5P5kQn1KQ52u2eW8pKHTqcG50ffv0UlRcW0

2. Copy the encrypted password returned in the last line of the output which would look like a long scrambled string. Paste it before the TITLE statement in the /boot/grub/grub.conf file, like this:

# vi /boot/grub/grub.conf
....
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password --encrypted $6$GXGrYVEnbKXAnQoT$p64OkyclNDt4qM2q47GMsgNxJxQaclNs79gvYYsl4h07ReDtJpt5P5kQn1KQ52u2eW8pKHTqcG50ffv0UlRcW0
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
....
Note : Make sure the permissions of the /boot/grub/grub.conf file are set to read-only to not allow any one to modify it.
# ls -lrt /boot/grub/grub.conf
-rw-------. 1 root root 845 Oct 11 14:43 /boot/grub/grub.conf

3. Once this is done, future boots will require the password before GRUB will permit you to edit boot options.

RHEL 6 set GRUB password

Using plain-text passwords

Although not secure, but if you still want to set a user readable plain-text GRUB password, use the below procedure :

1. Edit /boot/grub/grub.conf in a text editor and add a new “password PASSWORD-GOES-HERE” line prior to the first title stanza, e.g.:

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password my-not-so-hidden-password
title Red Hat Enterprise Linux ...

2. Ensure permissions on grub.conf do not allow anyone but root to read it :

# chmod 600 /boot/grub/grub.conf
# ls -l /boot/grub/grub.conf 
-rw------- 1 root root 678 Feb 02 14:12 /boot/grub/grub.conf

Using MD5 hashes

As said earlier in the post, MD5 is widely-considered broken. But if you still want to use them, follow the procedure below :

1. Run grub-md5-crypt to generate the hashed password :

# grub-md5-crypt 
Password: 
Retype password: 
$1$vweqo$CLFlozZ6ELHjGmL.0.37..

Add a new “password –md5 HASH-GOES-HERE” line prior to the first title line, e.g.:

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password --md5 $1$vweqo$CLFlozZ6ELHjGmL.0.37..
title Red Hat Enterprise Linux ...

As a final best-practice step, ensure permissions on grub.conf do not allow anyone but root to read it :

# chmod 600 /boot/grub/grub.conf
# ls -l /boot/grub/grub.conf 
-rw------- 1 root root 678 Jan 29 18:27 /boot/grub/grub.conf

Reboot the system and try pressing p to enter the password to unlock and enable next features in grub list.

Filed Under: Linux

Some more articles you might also be interested in …

  1. asciiart Command Examples in Linux
  2. CentOS / RHEL : How to set chroot jail for vsftp for all the users
  3. Active Directory Users Unable to Login via SSH using SSSD and Getting “Permission Denied, Please Try Again” [CentOS/RHEL]
  4. tune2fs: command not found
  5. “error: Bind to port 2222 on 0.0.0.0 failed: Permission denied” – error while starting sshd service on CentOS/RHEL
  6. gnome-software: command not found
  7. How to install and Configure VNC (TigerVNC) server in CentOS / RHEL 7
  8. unzip: command not found
  9. How to debug systemd boot process in CentOS/RHEL 7 and 8
  10. Understanding TCP Wrappers (/etc/hosts.allow & /etc/hosts.deny) in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright