Create Linux user and group with Bash /Shell script

In this tutorial you will learn how to create bulk linx user and password using shell script.

Create a user list

#vim userlist
test1
test2
test3
test4
test5

Now, create a script file

#vim useradd.sh

#/bin/bash
for i in `cat /root/userlist`
do
useradd $i
echo "User $i create successfully"
done

give excute permisstion to script file

# chmod o+x user.sh

Now run script

#./ user.sh

As you seen above users created successfully. Now set password for created user.

Create script to generate users password

#vim pass.sh
#!/bin/sh
for i in `cat userlist.txt `
do
echo $i"@123" | passwd --stdin "$i"
echo "Password changed for $i "
done

Note: password for each user is username@123

Now run script to generate password

# chmod o+x pass.sh
#./pass.sh
Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment