Skip to content

Instantly share code, notes, and snippets.

@opello
Created June 13, 2013 01:05
Show Gist options
  • Save opello/5770467 to your computer and use it in GitHub Desktop.
Save opello/5770467 to your computer and use it in GitHub Desktop.
Helper scripts for managing student user accounts in a Linux environment. Teacher accounts are manually created, and can be setup in sudoers to have access to student accounts.
#!/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