I'm working on a project for one of my classes, and I'm totally new to shell scripts and kind of in shock right now. Anyway, my assignment is to write a simple script that adds users to the system based on usernames and passwords stored in another file (yes, passwords in plaintext - obviously security isn't an issue for the assignment).
I'm stumped on how to get the password assigned correctly. I've tried doing it with useradd -p as well as passwd (normally and by doing something like echo $PASSWORD | passwd --stdin). Apologies if this makes no sense, low on sleep due to finals week. :P
Here is my script thus far:
Code:
#! /bin/bash
#Variables
NEW_USERS="/home/blake/newusers.lst"
HOME_DIR="/home/"
#The script itself...
cat ${NEW_USERS} | \
while read USER PASSWORD
do
useradd -m -d ${HOME_DIR}${USER} ${USER}
echo "User $USER has been created"
done
Essentially it's just set up to create a passwordless account for each name in the file "newusers.lst". Any ideas on how I would go about telling it to add a password? I'd like to give a generic password and force users to change it as soon as they login as well.
Thanks!
Blake