0

This is really basic, but I'm new to this. So basically I've created a random string using date below, but I can't really figure out how to set that string as the password. I know I have chpasswd <<< "$username:$password", but the string is not set as $password right? The error code I'm getting is "password is referenced but not assigned". Btw, this is part of a larger script.

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

1 Answers1

0

Well, yeah ... that would be a correct message; you're not assigning the string.

password=$( date +%s%N | sha256sum | head -c 10 )
tink
  • 12,902
  • 4
  • 44
  • 47