我正在尝试生成一些 MD5 哈希以openssl
用于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