Click to See Complete Forum and Search --> : Adduser Script


homey
02-23-2003, 01:47 PM
Hey peoples,

I want to use my script to add a bunch of users with as little input from me as possible. My script gives the user a blank password so I don't have to put in a gazillion passwords.

Can someone tell me about a script that does something like this...

If this is your first login,then make the user change password....


Also, where would that script get located?


Here is the adduser script
__________________________________________

#!/bin/bash
#
MAX=5000
for ((n=1; n <=MAX ; n++))
do
##
GROUP=500 # Default Group
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
##
# Ask for username.
##
echo ""
echo -n "Username: "
read USERNAME
#
echo "Adding user: $USERNAME."
#
adduser $USERNAME -g$GROUP
passwd -f -u $USERNAME
#
done
#
# End

bwkaz
02-23-2003, 02:19 PM
You could always make their ~/.bash_profile (or ~/.profile) check for the existence of a certain hidden file in their home directory, and if it isn't there, run passwd and then create it.

Call the file something like ~/.pwdset or something.

~/.bash_profile (or ~/.profile) gets run whenever they log in, so it'll check for the file every time, but yeah.

If you ever want to force them to change their password, just delete the ~/.pwdset files.

homey
02-23-2003, 04:21 PM
Ok, I realize that this is not the most programming savvy way of doing things, but me thinks it is ok unless proven otherwise. :)

I modified the script to include a password expiration of 60 days. ( passwd -x 60 $USERNAME )

Then I set the date on the computer back 61 days before creating the users.

After the users are created, I put the date back to current status so when the user logs on for the first time, they have to change the password.
:D
___________________________________________

#!/bin/bash
#
MAX=5000
for ((n=1; n <=MAX ; n++))
do
##
GROUP=500 # Default Group
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
##
# Ask for username.
##
echo ""
echo -n "Username: "
read USERNAME
#
echo "Adding user: $USERNAME."
#
adduser $USERNAME -g$GROUP
passwd -x 60 $USERNAME
passwd -f -u $USERNAME
#
done
#
# End