Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
1  
There's no need to cat to a pipe, just use IO redirection; < pwdfile chpasswd. –  Chris Down Dec 13 '11 at 15:04
    
Thanks @ChrisDown, added –  MaxMackie Dec 13 '11 at 15:08
    
My busybox does not have chpasswd. –  michelemarcon Dec 13 '11 at 15:13
    
What is the output of passwd --version? –  MaxMackie 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 8:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.