2

As you already know from title, I want to configure an encrypted password for grub in /etc/grub.conf. I want to use a single script, where I will use grub-md5-crypt, enter my password that I want to encrypt, and sed that encrypted output in /etc/grub.conf. Second part is fine for me. but how to handle password prompt in the script:

[root@localhost ssh]# grub-md5-crypt 
Password: 
Retype password: 
$1$3L3j7$lkZs92MnlmQkVYiCH9dtJ.

How can I automatically save the encrypted password in a variable or manage it somehow, so that in the next line of my script I can sed it like this:

sed -i '/^[# ]*timeout.*/a $hashedpwd/' /etc/grub.conf

Please help

dig_123
  • 2,240
  • 6
  • 35
  • 59

1 Answers1

4
Hashvalue="$(echo -e "P@$$w0rd\nP@$$w0rd" | grub-md5-crypt 2>/dev/null | tail --lines=1)"

Example

$ echo $Hashvalue
$1$F9fFw$czx0UwjdaorHHXf1QHRzi1
slm
  • 15,396
  • 12
  • 109
  • 124
Vishnu
  • 220
  • 1
  • 8