这真的很基本,但我是新手。所以基本上我已经使用下面的日期创建了一个随机字符串,但我真的不知道如何将该字符串设置为密码。我知道我有 chpasswd <<< "$username:$password",但是字符串没有设置为 $password 对吗?我得到的错误代码是“密码被引用但未分配”。顺便说一句,这是更大脚本的一部分。
# User enters username without being
# prompted for it
read -p "$1" username
# User enters full name without being prompted
read -p "$2" full_name
# Get a random password
date +%s%N | sha256sum | head -c 10 # Use this string as password
# Creates an account
useradd "$username"
# Assign the password.
chpasswd <<< "$username:$password"