我正在尝试编写 gpg 解密脚本,因此需要在命令行上提供密码。根据手册页,有三种方法可以做到这一点:使用从文件读取,使用--passphrase-file从标准输入(或其他文件描述符)读取--passphrase-fd 0,或仅使用包含在命令行中--passphrase。以上所有内容也需要--batch设置,我做到了。
我最近的命令行尝试是:
echo "<password>" | gpg2 --no-tty --batch --passphrase-fd 0 -d -o /<path_to_destination>/$FILE_NAME $FILE
Run Code Online (Sandbox Code Playgroud)
这仍然会弹出一个对话框,要求输入密码。我在这里缺少什么?作为参考,如果它有所作为,我的密码确实包含一些特殊字符,例如&,但它似乎并没有抱怨。另外,gpg 版本是 2.1.9:
# gpg2 --version
gpg (GnuPG) 2.1.9
libgcrypt 1.7.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Home: ~/.gnupg
Supported algorithms: …Run Code Online (Sandbox Code Playgroud)