2

I'm using busybox with a limited passwd (I don't have --stdin option) and without chpasswd and I need to change the password of an user from bash. Here is my best result:

echo newpassword > pwdfile
echo newpassword > pwdfile
cat pwdfile | passwd myuser
Changing password for myuser
Enter the new password (minimum of 5, maximum of 8 characters)
Please use a combination of upper and lower case letters and numbers.
Enter new password:
Bad password: too simple.

Warning: weak password (continuing).
Re-enter new password:
passwd: The password for myuser is unchanged.

1 Answers1

2

Busybox has chpasswd(8) which is a utility best used to create/update a lot of users very quickly and with one command. It accepts data from STDIN in username:password form. That means that you can do something like this:

$ cat pwdfile | chpasswd

or

$ < pwdfile chpasswd

Note that pwdfile must have username:new_password syntax.

Then again, you could always edit /etc/shadow yourself -- but please don't.

nopcorn
  • 9,559
  • 1
    There's no need to cat to a pipe, just use IO redirection; < pwdfile chpasswd. – Chris Down Dec 13 '11 at 15:04
  • My busybox does not have chpasswd. – michelemarcon Dec 13 '11 at 15:13
  • What is the output of passwd --version? – nopcorn Dec 13 '11 at 15:21
  • passwd: invalid option -- - BusyBox v1.00 (2011.04.28-16:58+0000) multi-call binary

    Usage: passwd [OPTION] [name]

    Change a user password. If no name is specified, changes the password for the current user. Options: -a Define which algorithm shall be used for the password (Choices: des, md5) -d Delete the password for the specified user account -l Locks (disables) the specified user account -u Unlocks (re-enables) the specified user account

    – michelemarcon Dec 14 '11 at 08:03
  • Is the user you're changing the password for in both /etc/passwd and /etc/shadow? – nopcorn Dec 14 '11 at 15:01
  • Yes, it is present on both files. The user can log in and out normally. – michelemarcon Dec 14 '11 at 15:54
  • Can you try with a non-weak password? Maybe that's the issue. – nopcorn Dec 14 '11 at 16:22