I have this script in which a user can change its password using passwd transparently. The script itself is executed by root, launching it with
su - <user> -c "script"
I know it might not be very safe a way to launch the script but that is how it is and I have no lattitude to change that part.
My problem is that when called, passwd displays the following:
Changing password for user <user>.
Changing password for <user>
current (UNIX) password:
New UNIX password:
Retype new UNIX password:
Several things to note here:
Has anyone got any answer or tips regarding this situation ? Thanks a lot.
(First question here so do not hesitate to ask for more info.)
Try keying:
su - vartaghan -c passwd
onto the command line and then contrast that with keying:
passwd
onto the command line.
The answer is right there. Because you are using su
to implement the command it requires the password to be keyed in and then the passwd
command becomes active, which requires the password all over again.
Your best option would be to change the way that the menu
which runs for your users, starts this password changing shell, by simply issuing the passwd
command.
Edit: If you want to get rid of the I/O use something like:
(echo $1; echo $2; echo $2) | passwd &>/dev/null
Which requires that you run the script as myscript oldpassword newpassword
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.