Is there a way, to give www-data (apache) access on ssh-agent? I have a simple php (cli) script, which simply connects a remote ssh server and run a simple command. On CLI I first start ssh-agent and load key which I protected by a passphrase.
Load agent a key:
# eval $(ssh-agent -s)
# ssh-add /root/.ssh/id_rsa
PHP CLI script:
#!/usr/bin/php
<?php
$connection = ssh2_connect('host', 22);
if (ssh2_auth_agent($connection, 'username')) {
echo "Authentication Successful!
";
} else {
die('Authentication Failed...');
}
$stream = ssh2_exec($connection, 'sh int status');
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo stream_get_contents($stream_out);
On CLI this works fine, but when I run the above snippet under apache, I can't authenticate on remote ssh host. I think the issue is, that the php/apache has no access on the ssh-agent.
My question: is there a way to start ssh-agent and load key for apache, so that apache has access on it?