gpg 解密在 LINUX 中给出错误“无法在批处理模式下查询密码”

发布于 2024-12-05 13:47:22 字数 465 浏览 3 评论 0原文

你好,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恰似旧人归 2024-12-12 13:47:22

此错误使得逗号看起来不喜欢使用 shell_exec 运行(类似于 sudo/ssh 在使用 shell_exec 运行时警告需要 tyy)::

gpg: gpg-agent is not available in this session

如果直接从 shell 提示符运行它会发生什么?

另外,请确保您不在安全模式下:

shell_exec()(反引号的功能等效)
当 PHP 在安全模式下运行时,此功能被禁用。

使用 phpinfo()


检查该功能是否未禁用:

$ grep 'disable_functions' /etc/php.ini

< 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)::

gpg: gpg-agent is not available in this session

What happens if u run it directly from the shell prompt?

Also, make sure your not in safe mode:

shell_exec() (functional equivalent of backticks)
This function is disabled when PHP is running in safe mode.

Check with phpinfo()


check that the function is not disabled:

$ grep 'disable_functions' /etc/php.ini

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.

泼猴你往哪里跑 2024-12-12 13:47:22

我遇到了从 cron 调用 gpg 的类似问题。
从命令行或 shell 脚本运行时,该命令工作正常。从 cron 运行命令失败,并出现与您遇到的相同错误。
我发现两个资源是很好的 gpg cheetsheet
以及这个答案serverfault

在生成 gpg 密钥后我能够让它工作。

gpg --gen-key

然后用以下方法加密:

gpg -e -r [email protected] backup_file.tgz

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.

gpg --gen-key

And then encrypt with:

gpg -e -r [email protected] backup_file.tgz
梦回旧景 2024-12-12 13:47:22

为了使用相关密码文件解密 gpg 加密文件并通过应用上下文运行它,请使用以下公式:

gpg --no-tty --no-use-agent --yes --passphrase-file <pass-phrase-file>
    --output <decrypted-file-path> --decrypt <encrypted-file-path>

示例

$ cd /home/app/gpg_example

$ ls -la
-rwxr-xr-x 3 user root 1000 Jan  1 00:00 secret_passphrase.txt
-rwxr-xr-x 3 user root 7000 Jan  1 00:00 encrypted-file.tar.gpg

$ gpg --no-tty --no-use-agent --yes --passphrase-file secret_passphrase.txt
--output decrypted-file.tar --decrypt encrypted-file.tar.gpg

$ ls -la
-rwxr-xr-x 3 user root 1000 Jan  1 00:00 secret_passphrase.txt
-rwxr-xr-x 3 user root 7000 Jan  1 00:00 encrypted-file.tar.gpg
-rwxr-xr-x 3 user root 6970 Jan  1 00:00 decrypted-file.tar # <= that's decrypted file.

In order to decrypt gpg encrypted files using relevant passphrase file and running it through an applicative context, use the following formula:

gpg --no-tty --no-use-agent --yes --passphrase-file <pass-phrase-file>
    --output <decrypted-file-path> --decrypt <encrypted-file-path>

example:

$ cd /home/app/gpg_example

$ ls -la
-rwxr-xr-x 3 user root 1000 Jan  1 00:00 secret_passphrase.txt
-rwxr-xr-x 3 user root 7000 Jan  1 00:00 encrypted-file.tar.gpg

$ gpg --no-tty --no-use-agent --yes --passphrase-file secret_passphrase.txt
--output decrypted-file.tar --decrypt encrypted-file.tar.gpg

$ ls -la
-rwxr-xr-x 3 user root 1000 Jan  1 00:00 secret_passphrase.txt
-rwxr-xr-x 3 user root 7000 Jan  1 00:00 encrypted-file.tar.gpg
-rwxr-xr-x 3 user root 6970 Jan  1 00:00 decrypted-file.tar # <= that's decrypted file.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文