سؤال

This is the script I wrote to create and assign password for new user.

$ssh->exec('useradd web3 -s /bin/false -d /var/www/web1 -g ftp-users');
$ssh->enablePTY(); 
$ssh->exec('passwd web3');
$ssh->read('Geben Sie ein neues UNIX-Passwort ein:');
$ssh->write("web3\n");
$ssh->read('Geben Sie das neue UNIX-Passwort erneut ein:');
$ssh->write("web3\n");

I tried it without enablePTY so instead of exec there is the write function but still it doesnt work, the user is created the first exec line is working but not changing the password for user web3

هل كانت مفيدة؟

المحلول

Maybe try doing $ssh->read('passwd: password updated successfully') after the last write(). In my testing it seems like there needs to be a little bit of a delay between when the password confirmation was entered and when the SSH session is closed. If you do exit right after the last write without waiting for at least a little bit of time the password change won't be "saved"

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top