使用 shell_exec('passwd') 更改用户密码 [英] Using shell_exec('passwd') to change a user's password
本文介绍了使用 shell_exec('passwd') 更改用户密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够通过网页(在受控环境中)更改用户的密码.因此,为此,我正在使用此代码:
I need to be able to change the users' password through a web page (in a controlled environment). So, for that, I'm using this code:
<?php
$output = shell_exec("sudo -u dummy passwd testUser testUserPassword");
$output2 = shell_exec("dummyPassword");
echo $output;
echo $output2;
echo "done";
?>
我的问题是该脚本没有更改用户testUser"的密码.我做错了什么?
My problem is that this script is not changing the password for the user "testUser". What am I doing wrong?
谢谢
推荐答案
另一种选择是有一个 shell 脚本,比如在某个地方叫做 passwd_change.sh,看起来像这样:
Another option is to have a shell script, say called passwd_change.sh somewhere that looks like this:
#!/usr/bin/expect -f
set username [lindex $argv 0]
set password [lindex $argv 1]
spawn passwd $username
expect "(current) UNIX password: "
send "$password\r"
expect "Enter new UNIX password: "
send "$password\r"
expect "Retype new UNIX password: "
send "$password\r"
expect eof
然后在您的 php 代码中执行:
Then in your php code do:
<?php
shell_exec("sudo -u root /path/to/passwd_change.sh testUser testUserPass");
?>
这篇关于使用 shell_exec('passwd') 更改用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文