Create multiple users with single command

Create multiple users using shell script, if you get an requirement  to create users you have to spend lot of time but here sharing script which will execute in a minute and create number of users. Prepare a list if users you wanted to create and input this shell script as a file.

## Date: 9th April 2016
## Purpose: Creating Multiple-users in a single attempt
## Author: Ankam Ravi Kumar
## WebSite:
if [ "$#" = 0 ]; then
 echo "Usage: /scripts/ file"
else if [ -f "$1" ]; then
 for i in `cat $1`; do useradd -s /bin/bash $i; done
 for y in `cat $1`; do echo -e "password\npassword" | passwd $y; done
 for z in `cat $1`; do cat /etc/passwd |grep $z; done
else echo "$1 not found"

Create Script file for create multiple users

[root@server scripts]# mkdir /scripts/
[root@server scripts]# vim /scripts/
PASTE above script here
:wq! (Save & Exit)

Change the permission script file

[root@server scripts]# chmod u+x /scripts/

Create a file with users list and execute

[root@server scripts]# vim file
[root@server scripts]# sh /scripts/ file

default password for created users is password

That’s it.

Please do comment your feedback

Related Articles

Linux basic commands

Monitoring websites using webinject

remove keypair using ansible AWS

AWS Tutorial

Thanks for your wonderful Support and Encouragement