通过服务器A上的
PHP运行SSH命令到服务器B.
要使用PHP在Linux上运行命令,请使用exec()命令.
我希望这会让你开始寻找正确的方向.
查看这两个帖子以自动化密码提示
这是一个使用非工作代码的快速示例,可以让您思考:
$server = "serverB.example.org";
//ip address will work too i.e. 192.168.254.254 just make sure this is your public ip address not private as is the example
//specify your username
$username = "root";
//select port to use for SSH
$port = "22";
//command that will be run on server B
$command = "uptime";
//form full command with ssh and command, you will need to use links above for auto authentication help
$cmd_string = "ssh -p ".$port." ".$username."@".$server." ".$command;
//this will run the above command on server A (localhost of the php file)
exec($cmd_string, $output);
//return the output to the browser
//This will output the uptime for server B on page on server A
echo '
';
print_r($output);
echo '
';?>
建议的流程是在服务器A上运行命令到SSH到服务器B.