Write a script, add 100 users

Specific requirements: 1, to create 100 users (user1, user2 ...... user100), a unified password 3dwtchpa, and enables remote login.

First, create a directory

#mkdir /shell

#cd /shell

Second, scripting

#vi useradd100.sh

#!/bin/bash

USER_FILE =. / User.info # password storage file

for USER in user {1..100} # variable USER user100 from user1 to start the cycle, generating a user 100

do

  if! id $ USER &> / dev / null # If the user does not exist

  then # then

        PASS = 3dwtchpa # unified password

        useradd $ USER # Add User

        echo $ PASS | passwd --stdin $ USER # change a user's password

        echo "$ USER $ PASS" >> $ USER_FILE # Save Password

        echo "$ USER create successful, pass is $ PASS." # Tip: You successfully created, the password is

  Then else #

        echo "$ USER User already exit" # prompt the user already exists

  be

done

Third, script execution

#chmod +x useradd.sh

#./useradd.sh

Guess you like

Origin blog.51cto.com/14413105/2439907