gpg 加密失败:文件打开错误

发布于 2024-11-25 02:45:58 字数 488 浏览 0 评论 0原文

我已经为此发疯了..

我在 CentOS 服务器上安装了 gnupg,并尝试加密上传的文件(通过 PHP 页面上传)。在服务器上通过命令行,它运行得很好。但是通过 php 脚本,它会失败并出现以下错误:

gpg: /path-to-my-file/my-file: encryption failed: file open error

用户 apache (我认为用于运行 exec 命令)在文件的目录中具有读/写权限。

文件上传正常(当我从代码中删除未加密文件的删除后我可以看到它)并且可以通过 php 站点正确删除。

我运行的命令如下 知道

/path-to-gpg/gpg --homedir=/path-to-my-home-gnupg/.gnupg -e -r therecipient@email the-unencrypted-file

如何解决这个问题吗? 谢谢

I have been going nuts with this..

I have gnupg installed on my CentOS server and I try to encrypt uploaded files (uploaded via a PHP page). On the server via the command line, it works perfectly. But via the php script, it fails with this error:

gpg: /path-to-my-file/my-file: encryption failed: file open error

The user apache (which I think is used to run the exec command) has read/write in the directory of the file.

The file is uploaded fine (I can see it afterward as I removed the deletion of the unencrypted file from my code) and can be deleted correctly via the php site.

the command I run is the following

/path-to-gpg/gpg --homedir=/path-to-my-home-gnupg/.gnupg -e -r therecipient@email the-unencrypted-file

Any idea how I could tackle this?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

∞觅青森が 2024-12-02 02:45:58

有几件事需要检查:

  • 运行 system("ls " .escapeshellarg($file)) 并检查结果 - 是否找不到文件?没有权限?这将帮助您调试。
  • 运行 system("whoami") 以确保 PHP 按照您认为的方式运行。
  • 运行 echo "
    ls " 。 escapeshellarg($file) 。 "

    " 然后复制+粘贴命令并从 shell 运行它,以确保文件的路径是您期望的路径。

另外,我相信 CentOS 默认运行 SELinux…如果您安装了它,请检查日志(在 /var/log/ 中)以查看 SELinux 是否阻止 Apache 执行 GPG。

A few things to check:

  • Run system("ls " . escapeshellarg($file)) and check the result — is it file not found? Permission denied? That will help you debug.
  • Run system("whoami") to make sure PHP is running as who you think it is.
  • Run echo "<pre>ls " . escapeshellarg($file) . "</pre>" then copy+paste the command and run it from the shell to make sure that the path to the file is what you expected it to be.

Also, I believe CentOS runs SELinux by default… If you've got it installed, check the logs (in /var/log/) to see if SELinux is preventing Apache from executing GPG.

岁月静好 2024-12-02 02:45:58

尝试在详细模式下使用实际的 apache 用户权限运行命令:

su apache -c /path-to-gpg/gpg -vv ...

Try running the command with actual apache user privileges in verbose mode:

su apache -c /path-to-gpg/gpg -vv ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文