To change the password, I can run the following
echo "user:$npasswd" | chpasswd. ...but after executing this it asks me to enter the current password.
Is there a way to automatically provide it with the current password?
01 Answer
as a user:
$ echo "rinzwind:2" | chpasswd
Changing password for rinzwind.
chpasswd: (user rinzwind) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user rinzwind) password not changedas root:
root@schijfwereld:~# echo "rinzwind:1" | /usr/sbin/chpasswd
root@schijfwereld:~# You need to do it as "root". ANY other method of course will ask for the current password. It would be a security issue if you could alter it
When you do it as "root" it also accepts short passwords as you can see. Setting "1" as a password is not allowed by default from a normal prompt.
You can do
$ echo -e "1\naaaabbbb\naaaabbbb" | passwd rinzwindwhere 1 is the old password and aaaabbbb is the new password. The flow of passwd is: old password, enter, new password, enter, new password. Mind that the password is visible (if only for a brief moment) in the processlist.
5