0
我想產生一些具有MD5哈希openssl
爲使用chpasswd
腳本生成的OpenSSL
防爆MD5哈希值。 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
我相信領先的'$ 1 $'表示密碼。實際加密或消化的密碼是'K8m2T $ gb3C0Sz4JlXyewe8VRhxv.'。 ('$'是'passwd'文件中的分隔符)。 – jww