Reputation: 1576
I'm looking for a solution to SSH through an existing SSH connection and execute a command with PHP. I've had this working with a simple command. Example:
$result = shell_exec("ssh user@server1 ssh user@server2 ls");
This works when run through CLI but not CGI. I've worked a bit with PHPSecLib but cannot figure out how to open the second connection, once I have a connection to server1.
Anyone have any advice?
Upvotes: 2
Views: 213
Reputation: 4492
When running through CGI, your PHP script probably runs as the web server user, and that user doesn't have access to your SSH keys. Either give the web server user your SSH keys or arrange for the PHP script to run as your user e.g. using suPHP.
And make sure to secure your application so your keys don't get stolen :)
Upvotes: 1