Skip to content

Instantly share code, notes, and snippets.

@napcs
Forked from opello/make-user-accounts.sh
Created June 13, 2013 01:57
Show Gist options
  • Save napcs/5770708 to your computer and use it in GitHub Desktop.
Save napcs/5770708 to your computer and use it in GitHub Desktop.
#!/bin/bash
PREFIX=$1
COUNT=$2
PASS=$3
# validation
if [ $# -ne 3 ]; then
echo "Usage: $0 <prefix> <count> <password>"
exit
fi
# hash password
PASS=$(openssl passwd -1 $PASS)
# create
for i in $(seq 1 $COUNT)
do
# setup student account, zero padded to two characters
# with a password
S=$(printf "${PREFIX}%02d" $i)
D=/home/$S
useradd -m -p $PASS -s /bin/bash $S
if [ $? -eq 0 ]; then
# remove group/other read/execute access
chmod 700 $D
# fix .bashrc for default PuTTY character set
echo -e "\nexport LANG=en_US.iso88591" >> $D/.bashrc
# fix wall/talk to prevent annoying students
echo -e "\nmesg n" >> $D/.bashrc
echo "Created $S"
else
echo "Could not create $S"
fi
done
#!/bin/bash
PREFIX=$1
COUNT=$2
# validation
if [ $# -ne 2 ]; then
echo "Usage: $0 <prefix> <count>"
exit
fi
# remove
for i in $(seq 1 $COUNT)
do
# setup student account, zero padded to two characters
# with a password
export S=$(printf "${PREFIX}%02d" $i)
userdel -r $S
if [ $? -eq 0 ]; then
echo "Removed $S"
else
echo "Could not remove $S"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment