【发布时间】:2019-07-06 23:58:55
【问题描述】:
我正在尝试以编程方式生成用户和密码,然后对密码进行哈希处理并将其存储在 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 命令?
或
如果有另一种更优雅的方法,我会怎么做?
【问题讨论】:
-
或许您可以使用流程替换来实现您的目标。
-
我正在使用这个显然允许它的示例github.com/ryran/burg2-mkpasswd-pbkdf2/blob/master/README.md
-
如果你的脚本在内存中包含变量,让脚本将密码写入文件并不能真正提高安全性。