Skip to content

Instantly share code, notes, and snippets.

@stripedpurple
Last active March 30, 2017 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stripedpurple/7760c5289e92f5efb4a197cbf935e527 to your computer and use it in GitHub Desktop.
Save stripedpurple/7760c5289e92f5efb4a197cbf935e527 to your computer and use it in GitHub Desktop.
create multiple users at once on Ubuntu
#!/bin/bash
# Batch creates users
# Tested on Ubuntu Server 16.04
# author: Austin Barrett
# thanks to Surendra Anne | http://www.linuxnix.com/create-multiple-users-linux/
if [[ -z $1 ]]; then
echo -e "Script Usage:\n\t./$(basename $0) user1 user2 user3... userN"
exit 1
fi
for i in $@
do
# adds user
useradd $i
# generates password
password=$(< /dev/urandom tr -dc A-Na-n1-9_ | head -c8 )
# sets user password
echo -e "$password\n$password" | passwd $i
# adds current user to master password list
echo -e "Username:$i" > /home/admin/useraccounts
echo -e "password:$password\n" >> /home/admin/useraccounts
# Configuring default shell as bash and setting up user home directories
usermod -s /bin/bash $i
mkhomedir_helper $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment