如何将 GnuPG 与 --passphrase 一起使用?

11 bash gnupg

我想编写一个脚本,该脚本将gpg使用密码“test”运行一个名为“file”的文件。

通常,当我使用 时gpg,我通常只是运行gpg -c file并询问我的密码。但是因为我希望这个脚本自己做所有事情,所以我想提供密码作为命令的一部分。

现在,当我尝试使用: 时gpg -c file --passphrase test,它输出:

用法:gpg [选项] --对称 [文件名]

它希望我使用哪个接缝gpg --passphrase test --symmetric file。但是如果我这样做,它会弹出一个对话框,询问我要使用的密码;这不是我想要的。

如何正确设置参数?

Jen*_*rat 7

在 GnuPG 中,选项必须在命令之前,因此--passphrase选项必须在--symmetric.

关于 pin 输入窗口,无论如何都会弹出(尽管您使用--passphrase),您可能已经在使用 GnuPG 2,它需要--batch--passphrase. 从手册页:

--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 system. 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
    GnuPG version 1.x.
Run Code Online (Sandbox Code Playgroud)

请注意,在多用户系统上,所有其他用户都可以读取您的命令行,因此也可以在执行 GnuPG 时读取密码。最好使用其他--passphrase-*选项之一来读取文件或管道。