3

我正在尝试使用 phpseclib 通过其 NET_SSH2 函数更改我的远程服务器的密码。下面是我正在使用的。

    <?php
    require_once('Net/SSH2.php');

    $ssh = new Net_SSH2('server1.server.com');
    if (!$ssh->login('user', 'pass')) {
        exit('Login Failed');
    }

    $ssh->write("passwd\n");
    $ssh->read('(current) UNIX Password:');
    $ssh->write("oldpass\n");
    $ssh->read('New password:');
    $ssh->write("newpass\n");
    $ssh->read('Retype new password:');
    $ssh->write("newpass\n");
    echo $ssh->read('[prompt]');

    ?>

每次我的脚本只是挂起并且似乎没有做任何事情。有什么我可能做错了吗?

这是关于此的文档:http: //phpseclib.sourceforge.net/documentation/net.html

4

2 回答 2

2

这可能会帮助你

<?php
$output = shell_exec('sudo passwd root');
echo "<pre>$output</pre>";
?>

shell_exec您可以通过函数执行任何linux命令

于 2012-04-26T10:52:40.300 回答
1

这应该适合你

<?php
    include('Net/SSH2.php');

    $ssh = new Net_SSH2('www.domain.tld');
    if (!$ssh->login('username', 'password')) {
        exit('Login Failed');
    }

    echo $ssh->read('username@username:~$');
    $ssh->write("passwd\n");
    echo $ssh->read('(current) UNIX password:');
    $ssh->write("oldpassword\n");
    echo $ssh->read('New UNIX password:');
    $ssh->write("newpassword\n");
    echo $ssh->read('Retype new UNIX password:');
    $ssh->write("newpassword\n");
    echo $ssh->read('passwd: all authentication tokens updated successfully.');

?>
于 2013-01-31T20:04:19.773 回答