openssl
で使用するMD5 ハッシュを生成しようとしていますchpasswd
元。CSV ファイル:
Sample,User,SU,,sauser,password
Test,User,TU,,teuser,password
User, T Test,TEST,,username,password
私が作成したスクリプト:
#!/bin/bash
file=$(readlink -f "$1") # open csv
while read line; do
salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1) #randomly generate 5 char salt
user=$(echo "$line" | cut -d, -f5 | xargs) # cut user from csv and trim with xargs
pass=$(echo "$line" | cut -d, -f6 | xargs) # cut pass from csv and trim with xargs
echo "$user:"$(openssl passwd -1 -salt "$salt" "$pass") >> ./global_chpasswd.data # gen MD5 hash per user and store in file
done < "$file" # close csv
ただし、このスクリプトから生成された MD5 を取得して chpasswd で使用しようとすると、機能しません。
echo 'username:$1$K8m2T$gb3C0Sz4JlXyewe8VRhxv.' | chpasswd -e
このパスワードは失敗します
手動でスクリプトを使用せずにこれを実行しようとすると、次のように機能します。
echo "username:"$(openssl passwd -1 -salt salt password) | chpasswd -e