0

I am using PHP to ssh into a main computer and run a command. My code is posted below but I'm stuck having the following issue:

When I run this command from the Ubuntu command line it works flawlessly. However when I try and run it via the web page I believe the ssh commands are not running. Not sure if I am running into issues with permissions, or if I am running into issues with my actually ssh command in php. Any help would be appreciated.

    $cmd = "ssh name@ip 'echo hello'";
    $var = shell_exec($cmd);
    echo $var;
2
  • 3
    maybe the user that you use in command line and web server have different permissions? Commented Aug 7, 2012 at 15:21
  • As below, ssh is usually not allowed on any security-minded hosting company! ... It may allow direct, but not via web server. Commented Aug 7, 2012 at 15:39

2 Answers 2

3

Rather than using shell_exec (which may be disabled for security reasons), look into using libssh2.

Reference: http://php.net/manual/en/book.ssh2.php

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

Comments

0

My guess would be that the user that the webserver runs as doesn't have your private key file in its ~/.ssh directory.

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.