如何使 PHP shell_exec 可以访问 GPG 密钥
我正在编写一个需要通过命令行运行 perl 脚本的脚本(使用 shell_exec()
)。为了设置脚本,我需要在我的一端生成一个 GPG 密钥,并将其公钥导入到我的 GPG 密钥环中。
当我以 ROOT 用户身份运行时,perl 脚本工作正常,但是当通过 PHP 运行时,它会抛出此错误消息:
“尝试签署请求时发生错误”
我认为这意味着 GPG我在 root 用户中设置的密钥对于 PHP 运行其 shell 命令的用户(即 apache)来说是无法访问的。
我应该如何解决这个问题?
我不知道我是否需要以 apache 身份登录并导入密钥,或者是否有一个命令以 root 身份运行以允许它们共享给 apache 用户...任何想法都很棒:)
I am working on a script that needs to run a perl script via command line (using shell_exec()
). To set up the script I needed to generate a GPG key on my end, and import their public key into my GPG keyring.
The perl script works fine when I run it as the ROOT user, but when running through PHP it throws this error message:
"An error occured when attempting to sign the request"
I assume this means that the GPG keys I have set up in my root user are not accessible to the user PHP is running its shell commands under (i.e. apache).
How should I go about solving this?
I don't know if I need to login as apache and import the keys, or if there is a command to run as root to allow them to be shared to the apache user... Any ideas would be great :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以在apache用户下运行一个shell,如下所示:
然后你可以初始化GPG。请注意,apache 的默认主目录是 /var/www,您可能必须:
要启用 GPG 来创建 .gnupg 子目录
you can run a shell under the apache user like this:
then you can initialize GPG. Note the default home directory for apache is /var/www, you might have to:
to enable GPG to create the .gnupg subdirectory
正确的。显然,您不希望像“apache”这样的普通用户能够以 root 身份签署内容!
因此,您需要为 apache 用户配置 GPG。这通常很痛苦,因为 apache 用户通常无法获得 shell。
我会尝试设置
/home/
目录,如果它不存在(可能不存在)。然后尝试为 apache 用户设置 GPG。您可以通过将--homedir=/home/
传递给 gpg 二进制文件来使其以 root 身份工作。Correct. Obviously, you don't want some mere mortal user like "apache" being able to sign things as root!
So you'll want to configure GPG for the apache user. This is usually painful, since the apache user typically can't get a shell.
I'd try setting up
/home/<apache-user>
directory, if it doesn't exist (probably doesn't). Then try setting up GPG for the apache user. You can probably get it to work as root by passing--homedir=/home/<apache-user>
to the gpg binary.