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.

#!/bin/bash
## Date: 9th April 2016
## Purpose: Creating Multiple-users in a single attempt
## Author: Ankam Ravi Kumar
## WebSite: http://www.arkit.co.in/
if [ "$#" = 0 ]; then
 echo "Usage: /scripts/createuser.sh 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"
fi
fi

Create Script file for create multiple users

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

Change the permission script file

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

Create a file with users list and execute

[root@server scripts]# vim file
aravi
kumar
user1
[root@server scripts]# sh /scripts/createuser.sh 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

More than 40,000 techies are part of our ARKIT community. Join us today and keep learning Linux, Cloud, Storage, DevOps, and IT technologies.

Get Email Updates Download E-Books Facebook Page YouTube Channel Twitter Join Telegram Group Join WhatsApp Group
author avatar
Ravi Kumar Ankam
My name is Ravi Ankam. I am passionate about learning new technologies quickly and sharing knowledge with others. My goal is to help learners grow their skills, because the more you learn, the more you earn. See About Me

Ravi Kumar Ankam

My name is Ravi Ankam. I am passionate about learning new technologies quickly and sharing knowledge with others. My goal is to help learners grow their skills, because the more you learn, the more you earn. See About Me

13 Responses

  1. Venkata G Thota says:

    If you have the same for solaris & AIX for multiple users creation then please share

  2. akram ahmed says:

    If your in Hyderabad only can you please tell if there any Chance to have an opportunity to get job in this Field only because I know the Linux as well as mcse

  3. Amar Tiwari says:

    that is good…but what about if want to pass word also..

  4. Jitendra says:

    Hi Ravi

    Nice script but instead of this line (echo -e “password\npassword” | passwd $y), we can write like this (echo “password” | passwd –stdin $y).

  5. Harshad says:

    I want create my own game server. Have u know the configurations about that.

  6. We have rocks cluster & I want to analyze disk space of /export/home/users & /exports/scratch directory disk utilization per user.

  7. harish says:

    Scripts is not working

  8. Krishna says:

    Ravi thanks for showing this script….
    I already did that…
    Can you please share some session about no login user creation. Adding groups in line with user with a script.

Leave a Reply

Your email address will not be published. Required fields are marked *