パスワードスクリプトの変更

パスワードスクリプトの変更

user:password形式のユーザー名と暗号化されたパスワード(openssl passwd)を含むファイルがあります。
Cronjobを使って週に一度このユーザーのパスワードを変更したいと思います。
の助けを借りてヤノス$RANDOMで生成された値でパスワードを変更し、暗号化されたパスワードはpw.txtに、暗号化されていないパスワードはrandompw.txtに保存するスクリプトを作成しました。

r=$RANDOM
cut -d: -f1 pw.txt | while read -r user; do
    echo "$user:$(openssl passwd $r)"
done > newpw.txt
mv newpw.txt pw.txt
echo $r > randompw.txt

だから私の質問は次のとおりです。
1.) これにより、各ユーザーにランダムに生成された値を提供するだけですが、各ユーザー(ファイルの各行)にランダムな値を提供したいと思います。
2.) 各ユーザーのユーザー名とプレーンテキストのパスワードを randompw.txt に入れることができれば良いでしょう。現在、そこには$RANDOMパスワードが1つしかありません。

誰でもどんなアイデアがありますか?

古い投稿

ベストアンサー1

生成されたパスワードを変数に保存し、2つのファイルに書き込むことができます。

  • 明確な文書
  • ファイルがハッシュされました。

たとえば、

# initialize (truncate) output files
> clear.txt
> hashed.txt

cut -d: -f1 pw.txt | while read -r user; do        
    # generate a hash from a random number
    hash=$(openssl passwd $RANDOM)

    # use the first 8 letters of the hash as the password
    pass=${hash:0:8}

    # write password in clear formats to one file, and hashed in another
    echo "$user:$pass" >> clear.txt
    echo "$user:$(openssl passwd $pass)" >> hashed.txt
done

おすすめ記事