0

I'm doing this:

$user = 'kevin';
$pass = 'nivek';
shell_exec('echo -e "' . $pass . '\n' . $pass . '" | sudo passwd ' . $user);`

But when I execute this, I get this error:

Enter new UNIX password: Retype new UNIX password: Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged

Why? How can I solve this and how can I hide the output from passwd?

4
  • Does the command work in console? Commented Apr 8, 2011 at 12:21
  • cyberciti.biz/tips/… Commented Apr 8, 2011 at 12:32
  • No, --stdin gives an error here. Commented Apr 8, 2011 at 13:14
  • Thanks, Wh1T3h4Ck5 (what a name ;p). It's working!! :D Commented Apr 8, 2011 at 14:01

2 Answers 2

2

Use --stdin for passwd to read from standard input. Then you can pipe the password.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the following code:

$user = 'kevin';
$pass = 'nivek';
shell_exec('echo -e "' . $pass . '" | sudo passwd --stdin ' . $user);

That appears to work for me (although tested without sudo, you may need the second).

I'm not sure that sudo would even work.

2 Comments

Sorry, wrong comment. Got this error: passwd: unrecognized option '--stdin'
What distro are you using? This works fine on Red Hat (and derivatives) at least.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.