我需要从另一台计算机或同一台计算机上使用ssh执行位于/ root/scripts/php中的perl脚本。事情是,我只是不知道如何使PHP登录到根帐户,以只优先于该文件。我该如何运行需要root权限的perl脚本?
由于用户$我无法访问/ 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
?>
我希望你能帮助我在这里。
当你已经使用登录到root的时候,你为什么要执行sudo su? – bwoebi 2013-04-23 19:56:22
对不起,我没有注意到我在有用户的地方留下了根,在我写这个问题之前,这只是一个测试,我忘记了将用户放回去。 – 2013-04-23 20:05:13
通过ssh的远程root是一个巨大的安全漏洞。你会更好地以普通用户身份登录,然后授予该用户sudo对特定脚本的访问权限。 – 2013-04-23 20:24:14