unix "passwd"コマンドに入力された新しいパスワードを表示

unix

実行可能ですか?パスワード新しく入力したパスワードを表示するオプションがあるコマンド?デフォルトでは、私が入力したものは表示されず、それをしたくありません。

[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.

ベストアンサー1

本当にこの道を行きたかったけどまだ行けなかったらパスワードパラメータ、これを使用できます予想されるスクリプト:

#!/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

仕組み:

[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.

このシェルスクリプトも機能します(bash-4.2.47-2とpasswd-0.79-2を使用してFedora 20でテスト済み)。

#!/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

仕組み:

[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.

おすすめ記事