gpg 解密在 LINUX 中给出错误“无法在批处理模式下查询密码”
你好,我使用 gpg 来解密 Linux 中的文件,我使用 gpg
shell_exec("gpg --batch --passphrase-file $passphrase_file -d $encrypted_file");
来解密该文件,但我收到以下错误。
gpg: gpg-agent is not available in this session
gpg: can't query passphrase in batch mode
gpg: Invalid passphrase; please try again ...
gpg: can't query passphrase in batch mode
gpg: Invalid passphrase; please try again ...
gpg: can't query passphrase in batch mode
Hi im using gpg to decrypt a file in linux, im using
shell_exec("gpg --batch --passphrase-file $passphrase_file -d $encrypted_file");
to decrypt the file, but im getting the following errors.
gpg: gpg-agent is not available in this session
gpg: can't query passphrase in batch mode
gpg: Invalid passphrase; please try again ...
gpg: can't query passphrase in batch mode
gpg: Invalid passphrase; please try again ...
gpg: can't query passphrase in batch mode
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此错误使得逗号看起来不喜欢使用 shell_exec 运行(类似于 sudo/ssh 在使用 shell_exec 运行时警告需要 tyy)::
如果直接从 shell 提示符运行它会发生什么?
另外,请确保您不在安全模式下:
使用 phpinfo()
检查该功能是否未禁用:
< strong>编辑:
另外,尝试使用 putenv 将 GNUPGHOME 指向您的 .gnupg 文件夹。
可能是 php 脚本以 httpd 用户身份运行,而 gpg 需要您的站点的“user”用户。
This error makes it appear that the commaand doesnt like to be run using shell_exec (similar to how sudo/ssh warns about needing a tyy when run with shell_exec)::
What happens if u run it directly from the shell prompt?
Also, make sure your not in safe mode:
Check with phpinfo()
check that the function is not disabled:
Edit:
Also, try using putenv to point GNUPGHOME to your .gnupg folder.
It could be that the php script is being run as the httpd user and the gpg is expecting the 'user' user for your site.
我遇到了从 cron 调用 gpg 的类似问题。
从命令行或 shell 脚本运行时,该命令工作正常。从 cron 运行命令失败,并出现与您遇到的相同错误。
我发现两个资源是很好的 gpg cheetsheet
以及这个答案serverfault
在生成 gpg 密钥后我能够让它工作。
然后用以下方法加密:
I ran into a similar problem calling gpg from cron.
The command works fine when run from the command line or from a shell script. Running the command from cron fails with the same errors you're getting.
Two resources I found were a good gpg cheetsheet
And this answer on serverfault
I was able to get it to work after generating a gpg key.
And then encrypt with:
为了使用相关密码文件解密 gpg 加密文件并通过应用上下文运行它,请使用以下公式:
示例:
In order to decrypt gpg encrypted files using relevant passphrase file and running it through an applicative context, use the following formula:
example: