bash – 解密目录中的多个OpenPGP文件

前端之家收集整理的这篇文章主要介绍了bash – 解密目录中的多个OpenPGP文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在目录中有几百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选项:
--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
原文链接:https://www.f2er.com/bash/387289.html

猜你在找的Bash相关文章