How to add users in batches under Linux

  

First, add regular users in batches

If you add user1, user2……user50, how many can be input interactively, and user prefixes are also input interactively. :

#!/bin/bash##Add User Scripts in Batches####Interactive Ways to Read User Prefixes and Number of Users####Passwords also use interactive input, user passwords are password prefixes + user serial numbers ## author: Barlow #### last modified: 2013-3-18 #### to create a user echo " Please input username: " read nameecho " Please input number of users: " read numn = 1while [ ,null,null,0],$n -le $num ]do/usr/sbin/useradd $name$n > /dev/null##You can also add new users to a group, such as the sshd group, so that they can log in to /usr/using ssh. Sbin/usermod -G sshd $name$nn=`expr $n + 1`done# Change password echo "Please input the password:"read passwdm=1while [ $m -le $num ]doecho $passwd$m |  /usr/bin/passwd --stdin $name$m > /dev/nullm=`expr $m + 1`doneexit

Second, add users without any rules in batches:

If you want to add a account to a server for the R&D department and the account is the full spell for each user, you can put these users' accounts into a specific file with less Read and create, the specific script is as follows:

#!/bin/bash##Add user scripts in batches####Read user names from user list file $1 and create ####Set all the user's password for the user name +888 #### author: Barlow #### last modified: 2013-3-18 ### for user in `less $ 1`do /usr /sbin /useradd $ user ## here You can also add new users to a group, such as the sshd group, so that they can use ssh to log in to /usr/sbin/usermod -G sshd $name$n#change the password echo $user"888" |  /usr/bin/passwd --stdin $userdoneexit

When executed, the following parameter is the user list file, such as:

sh useradd.sh user_list.txt

Copyright © Windows knowledge All Rights Reserved