简体   繁体   English

PHP ssh从命令行运行,而不从网页运行

[英]PHP ssh working from command line, not working from web page

I am using PHP to ssh into a main computer and run a command. 我正在使用PHP SSH进入主计算机并运行命令。 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. 当我从Ubuntu命令行运行此命令时,它可以正常工作。 However when I try and run it via the web page I believe the ssh commands are not running. 但是,当我尝试通过网页运行它时,我相信ssh命令没有运行。 Not sure if I am running into issues with permissions, or if I am running into issues with my actually ssh command in php. 不知道我是否遇到权限问题,或者我是否在php中的实际ssh命令遇到问题。 Any help would be appreciated. 任何帮助,将不胜感激。

    $cmd = "ssh name@ip 'echo hello'";
    $var = shell_exec($cmd);
    echo $var;

Rather than using shell_exec (which may be disabled for security reasons), look into using libssh2 . 与其使用shell_exec (出于安全原因可能禁用), libssh2使用libssh2

Reference : http://php.net/manual/en/book.ssh2.php 参考http : //php.net/manual/zh/book.ssh2.php

我的猜测是,运行Web服务器的用户的〜/ .ssh目录中没有您的私钥文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM