Ubuntu中echo "test" | password --stdin test 錯誤


今天看到了馬哥的視頻,講道理passwd命令和管道的標準輸入時,一個命令重置密碼。

我測試了一下報錯

echo "test" | password --stdin test


root@localhost:/home/test2# echo "test" | password --stdin test

未找到 'password' 命令,您要輸入的是否是:

 命令 'assword' 來自於包 'assword' (universe)

password:未找到命令

root@localhost:/home/test2# echo "test" | passwd --stdin test

passwd:無法識別的選項“--stdin”

Usage: passwd [options] [LOGIN]


Options:

  -a, --all                     report password status on all accounts

  -d, --delete                  delete the password for the named account

  -e, --expire                  force expire the password for the named account

  -h, --help                    display this help message and exit

  -k, --keep-tokens             change password only if expired

  -i, --inactive INACTIVE       set password inactive after expiration

                                to INACTIVE

  -l, --lock                    lock the password of the named account

  -n, --mindays MIN_DAYS        set minimum number of days before password

                                change to MIN_DAYS

  -q, --quiet                   quiet mode

  -r, --repository REPOSITORY   change password in REPOSITORY repository

  -R, --root CHROOT_DIR         directory to chroot into

  -S, --status                  report password status on the named account

  -u, --unlock                  unlock the password of the named account

  -w, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

  -x, --maxdays MAX_DAYS        set maximum number of days before password

                                change to MAX_DAYS


我看到這個錯誤,我以爲是passwd --stdin這個參數問題,於是我上網百度了一下,大家都說沒問題啊,

意外在Ubuntu論壇中發現了一個帖子

最近學習鳥哥的passwd用法時練習建立賬號並修改密碼(密碼統一爲“password”),程序如下
#!/bin/bash
groupadd myquotagrp
for username in myquota1 myquota2 myquota3 myquota4 quota5
do
useradd -g myquotagrp $username
echo "password" | passwd --stdin $username
done
運行後報錯
passwd: unrecognized option '--stdin'
Usage: passwd [options] [LOGIN]

Options:
-a, --all report password status on all accounts
-d, --delete delete the password for the named account
-e, --expire force expire the password for the named account
-h, --help display this help message and exit
-k, --keep-tokens change password only if expired
-i, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --lock lock the password of the named account
-n, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-q, --quiet quiet mode
-r, --repository REPOSITORY change password in REPOSITORY repository
-S, --status report password status on the named account
-u, --unlock unlock the password of the named account
-w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
-x, --maxdays MAX_DAYS set maximim number of days before password
change to MAX_DAYS

我又查了下passwd的用法,雖然不是很懂,但嘗試了openssl passwd -stdin
還是報錯:
Usage: passwd [options] [passwords]
where options are
-crypt standard Unix password algorithm (default)
-1 MD5-based password algorithm
-apr1 MD5-based password algorithm, Apache variant
-salt string use provided salt
-in file read passwords from file
-stdin read passwords from stdin
-noverify never verify when reading password from terminal
-quiet no warnings
-table format output as table
-reverse switch table columns


最後看到了其中一個信息

passwd的--stdin參數ubuntu不支持,其實debian就不支持這個,自己後來在centos7中測試了一下,可以,原理問題就出在這裏。

因爲我的系統是Ubuntu14.04的系統,終於找到問題的原因了。


後來在網上找到了一個方法就是換行,模擬兩次輸入密碼,但是發現還是不行,

root@localhost:/home/test2# echo "test\ntest" | passwd  test2

輸入新的 UNIX 密碼: 重新輸入新的 UNIX 密碼: passwd: 認證令牌操作錯誤

passwd: password unchanged


自己直接重置密碼可以。

root@localhost:/home/test2# passwd  test2

輸入新的 UNIX 密碼: 

重新輸入新的 UNIX 密碼: 

passwd: password updated successfully

root@localhost:/home/test2# 


自己想到這裏也沒有好的辦法了,希望高手也可以留言,幫忙解決一下吧







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章