我在目录中有几百gpg加密文件,格式为filename.xyz.gpg,其中“xyz”是一些任意扩展名。我需要解密所有的文件,以生成filename.xyz,这样我就不需要手动输入每个文件的密码。
我已经尝试了以下目录“测试”:
for file in 'ls Testing'; do (echo <password>|gpg --passphrase-fd 0 -d $file --output $file.decrypted);
我刚刚用命令提示符>结束,没有任何反应。
我的语法有什么问题?有没有一个更有效的方式来做这个没有bash shell循环?
正如手册中所说,您需要添加–batch选项:
原文链接:https://www.f2er.com/bash/387289.html--passphrase-fd n Read the passphrase from file descriptor n. Only the first line will be read from file descriptor n. If you use 0 for n,the passphrase will be read from STDIN. This can only be used if only one passphrase is supplied. Note that this passphrase is only used if the option --batch has also been given. This is different from gpg. --passphrase string Use string as the passphrase. This can only be used if only one passphrase is supplied. ObvIoUsly,this is of very questionable security on a multi-user sys‐ tem. Don't use this option if you can avoid it. Note that this passphrase is only used if the option --batch has also been given. This is different from gpg.
您可以使用以下两种形式之一:
echo "passphrase" | gpg --passphrase-fd 0 --batch -d --output "decrypted.file" "file.gpg"
或更简单:
gpg --passphrase "passphrase" --batch -d --output "decrypted.file" "file.gpg"
#!/bin/bash read -rsp "Enter passphrase: " PASSPHRASE for FILE in *.*.gpg; do echo "Extracting $FILE to ${FILE%.gpg}." echo "$PASSPHRASE" | gpg --passphrase-fd 0 --batch -d --output "${FILE%.gpg}" "$FILE" done