我需要使用来自另一台计算机或同一台计算机的 ssh 从 php 执行位于 /root/scripts/ 的 perl 脚本。问题是我只是不知道如何让 php 登录到 root 帐户以仅执行该文件。
作为用户 $ 我无法访问 /root/scripts/,所以我无法使用 excec 或 system 调用它。我曾尝试使用 ssh 登录 sudo su,但当我输入密码时,它会挂起。
我把代码留在这里:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('IP');
if (!$ssh->login('user', 'password')) {
exit('Login Failed');
}else{
echo ("login suscess");
}
echo $ssh->read(']$');
echo $ssh->write("sudo su\n");
echo $ssh->read('user:');
//the code normally runs if I dont write the lines below
$ssh->write('password\n');//here I try to get ssh the root pass but php wont respond after this
echo $ssh->read('user]#');//normally this would work to show the root prompt but I don't know what happens
?>
我希望你能在这里帮助我。