mcryan
mcryan

Reputation: 1576

PHP: SSH through an existing SSH connection

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

Answers (2)

user1469439
user1469439

Reputation:

What about $ssh->exec('ssh user@server2 ls')?

Upvotes: 0

mpartel
mpartel

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

Related Questions