2

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I created SSH keys for "apache" and all is working!
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.