Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make GPG keys accessible for PHP shell_exec

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

like image 640
Stephen RC Avatar asked Mar 02 '26 21:03

Stephen RC


2 Answers

you can run a shell under the apache user like this:

su apache -s /bin/ksh

then you can initialize GPG. Note the default home directory for apache is /var/www, you might have to:

chmod a+w /var/www

to enable GPG to create the .gnupg subdirectory

like image 169
Ole Avatar answered Mar 05 '26 10:03

Ole


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.

like image 42
timdev Avatar answered Mar 05 '26 10:03

timdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!