提问人:133U 提问时间:1/6/2023 最后编辑:133U 更新时间:1/9/2023 访问量:73
Bash 程序似乎不接受 EOF 输入,而是卡住了
Bash program appears to not accept EOF input and instead gets stuck
问:
我想自动化我的 Mint 安装。我的 Mint 安装的一个主要部分是使用 LUKS 分区对整个磁盘进行加密。为了能够通过我的Yubikey解锁我的设备,我必须运行以下行:
yubikey-luks-enroll -d /dev/sda3 -s 7
您可以通过安装获得并且工作正常。但是,使用 EOF 运行此命令不起作用。sudo apt install yubikey-luks
运行上述命令时,系统会要求我输入密码两次,然后输入 LUKS 部分的密码:
$ sudo yubikey-luks-enroll -d /dev/sda3 -s 7
setting disk to /dev/sda3.
setting slot to 7.
This script will utilize slot 7 on drive /dev/sda3. If this is not what you intended, exit now!
Adding yubikey to initrd
Please enter the yubikey challenge password. This is the password that will only work while your yubikey is installed in your computer:
Please enter the yubikey challenge password again:
Please provide an existing passphrase. This is NOT the passphrase you just entered, this is the passphrase that you currently use to unlock your LUKS encrypted drive:
我可以使用以下 bash 脚本自动执行此步骤:
read PART
read -s DISKPWD
read -s PWD1
read -s PWD2
sudo yubikey-luks-enroll -d $PART -s 7 <<-EOF
$PWD1
$PWD2
$DISKPWD
EOF
不幸的是,这只会导致以下输出:
setting disk to /dev/sda3.
setting slot to 7.
This script will utilize slot 7 on drive /dev/sda3. If this is not what you intended, exit now!
Adding yubikey to initrd
更糟糕的是,终端卡住了 - 你可以输入东西,但它没有效果。只需 CTRL + Z 即可。
如果有人想知道,我必须使用相同的凭据设置多个 Yubikey,这就是我想自动化该过程的原因。
我还尝试在没有EOF的情况下在终端中运行该命令,这工作正常。在终端中使用 EOF 运行命令会导致与上述相同的错误。删除 Bash 文件中的 EOF 时,该命令有效。
我不是一个有经验的 Linux 用户。也许这只是一个简单的错误。我希望一切都是可以理解和清楚的。
问候 133U
答:
0赞
jhnc
1/9/2023
#1
yubikey-luks-enroll 是一个 shell 脚本。
要读取密码,它会调用 ./lib/cryptsetup/askpass
因此,您可以简单地编写一个修改版本,替换调用。askpass
请注意安全地处理明文密码。
评论
yubikey-luks-enroll
read
yubikey-luks-enroll