php exec输入密码,php – 使用shell_exec(‘passwd’)更改用户的密码

我需要能够通过网页(在受控环境中)更改用户的密码.

所以,为此,我正在使用此代码:

$output = shell_exec("sudo -u dummy passwd testUser testUserPassword");

$output2 = shell_exec("dummyPassword");

echo $output;

echo $output2;

echo "done";

?>

我的问题是这个脚本没有改变用户“testUser”的密码.

我究竟做错了什么?

谢谢

解决方法:

另一个选择是有一个shell脚本,比如叫做passwd_change.sh,看起来像这样:

#!/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代码中执行:

shell_exec("sudo -u root /path/to/passwd_change.sh testUser testUserPass");

?>

标签:php,sudo,shell-exec,passwd

来源: https://codeday.me/bug/20190717/1485882.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值