我将尝试编写程序来自动生成用户名和密码,然后对密码进行哈希处理并将其存储在 grub 配置文件中。
目前,我已经有了以下内容:
目前,我已经有了以下内容:
# add a superuser account and password for the bootloader
## generate a secure password
pw=$(openssl rand -base64 32)
## create the new user for the bootloader and set the password as the secure password
useradd grub2superuseraccount
echo $pw | passwd grub2superuseraccount --stdin
## store the password to a TEMP file (needed to pass the password to grub2_mkpassword-pbkdf command, it will be deleted after)
cat << END >> ~/pfile
$pw
$pw
END
## generate the password hash and store it in the bootloader config file
cat ~/pfile | grub2-mkpasswd-pbkdf2 | sed -i "/password_pbkdf2/a password_pbkdf2 $THEVALUEOFTHEOUTPUTFROMTHEPIPE"
## delete the file with the password
rm ~/pfile
我该如何将“grub2-mkpasswd-pbkdf2”生成的哈希密码输出传递给sed命令?
或者
如果有更加简洁的方法,我该如何实现?