If you do passwd on yourself you'll be prompted for the old pw before being allowed to set the new pw. And on my Linux system I wasn't able to do passwd on another user without doing root. That may result in you being for your prompted for your password as well.
As a general rule, the way I found out what the prompt is is by doing $ssh->setTimeout() with an empty $ssh->read() call. eg.
$ssh->enablePTY();
$ssh->exec('sudo passwd testuser');
$ssh->setTimeout(3);
echo $ssh->read();
That outputs Enter new UNIX password:
. So I rewrite my program thusly:
$ssh->enablePTY();
$ssh->exec('sudo passwd testuser');
$ssh->setTimeout(3);
$ssh->read('password:');
$ssh->write("newpw
");
echo $ssh->read();
That outputs Retype new UNIX password:
. So I then revise my program accordingly:
$ssh->enablePTY();
$ssh->exec('sudo passwd testuser');
$ssh->setTimeout(3);
$ssh->read('password:');
$ssh->write("newpw
");
$ssh->read('password:');
$ssh->write("newpw
");
echo $ssh->read();
That outputs passwd: password updated successfully
. Now that I know it works I remove the $ssh->setTimeout(3) and update the last $ssh->read() to get this:
$ssh->enablePTY();
$ssh->exec('sudo passwd testuser');
$ssh->read('password:');
$ssh->write("newpw
");
$ssh->read('password:');
$ssh->write("newpw
");
$ssh->read('passwd:');
And that's it! It'll change the password without waiting for six seconds like your version does. That last $ssh->read() may not be necessary though. I'll let you play around with that.