PHP更改linux用户密码(passwd)

i want to change user passwords via my api, but my current code doesnt work.

Maybe someone could help me.

$cmd1 = "passwd ".$info['instanceFtpUser'];
$ssh->exec($cmd1."
");
$ssh->exec($newpass."
");
$ssh->exec($newpass."
");
$ssh->disconnect();

btw, i'm using phpseclib

Your use case is an example on the phpseclib docs: http://phpseclib.sourceforge.net/ssh/pty.html

As you can see you above you should use write to output to PTY, not exec:

$ssh->enablePTY(); 
$cmd1 = "passwd ".$info['instanceFtpUser'];
$ssh->exec($cmd1);
echo $ssh->read('password:'); 
$ssh->write($newpass."
"); 
echo $ssh->read('password:'); 
$ssh->write($newpass."
");
$ssh->disconnect(); 

You can also use sshpass (https://sourceforge.net/projects/sshpass/) it lets you ssh to a remote server without asking for password. you can create a script that ssh to the remote server and sets the new password. you can then call this script using the php exec function.