LINUX SHELL SCRIPT 分配随机字符串作为密码

问题描述

这真的很基础,但我是新手。所以基本上我已经使用下面的日期创建了一个随机字符串,但我真的不知道如何将该字符串设置为密码。我知道我有 chpasswd

# 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"

解决方法

嗯,是的……那将是一个正确的信息;您没有分配字符串。

password=$( date +%s%N | sha256sum | head -c 10 )