Last active
March 30, 2017 22:43
-
-
Save stripedpurple/7760c5289e92f5efb4a197cbf935e527 to your computer and use it in GitHub Desktop.
create multiple users at once on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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