Show entered new password in unix “passwd” command

command linepasswdpassword

Is is possible to run the passwd command with an option to show the newly entered passwords? By default it doesn't show what I type and I don't want this.

[dave@hal9000 ~]$ passwd 
Changing password for user dave.
Changing password for dave.
(current) UNIX password: 
New password: bowman
Retype new password: bowman
passwd: all authentication tokens updated successfully.

Best Answer

If you really want to go this path and there's no passwd parameter, you can use this Expect script:

#!/usr/bin/env expect -f
set old_timeout $timeout
set timeout -1

stty -echo
send_user "Current password: "
expect_user -re "(.*)\n"
set old_password $expect_out(1,string)

stty echo
send_user "\nNew password: "
expect_user -re "(.*)\n"
set new_password $expect_out(1,string)

set timeout $old_timeout
spawn passwd
expect "password:"
send "$old_password\r"
expect "password:"
send "$new_password\r"
expect "password:"
send "$new_password\r"
expect eof

How it works:

[dave@hal9000 ~]$ ./passwd.tcl
Current password: 
New password: bowman
spawn passwd
Changing password for user dave.
Changing password for dave.
(current) UNIX password: 
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

This shell script might also work (tested on Fedora 20 with bash-4.2.47-2 and passwd-0.79-2):

#!/bin/sh
stty -echo
echo -n "Current password: "
read old_password

stty echo
echo
echo -n "New password: "
read new_password

passwd << EOF
$old_password
$new_password
$new_password
EOF

How it works:

[dave@hal9000 ~]$ ./passwd.sh
Current password: 
New password: bowman
Changing password for user dave.
Changing password for dave.
(current) UNIX password: New password: Retype new password: passwd: all authentication tokens updated successfully.
Related Question