批量创建用户及密码
批量创建用户并设置密码不为相同
#!/bin/bash for n in `seq -w 10` do useradd xcn$n&&\ echo "root$n"|passwd --stdin xcn$n done 执行结果: [root@XCN for]# sh test7.sh Changing password for user xcn01. passwd: all authentication tokens updated successfully. Changing password for user xcn02. passwd: all authentication tokens updated successfully. Changing password for user xcn03. passwd: all authentication tokens updated successfully. Changing password for user xcn04. passwd: all authentication tokens updated successfully. Changing password for user xcn05. passwd: all authentication tokens updated successfully. Changing password for user xcn06. passwd: all authentication tokens updated successfully. Changing password for user xcn07. passwd: all authentication tokens updated successfully. Changing password for user xcn08. passwd: all authentication tokens updated successfully. Changing password for user xcn09. passwd: all authentication tokens updated successfully. Changing password for user xcn10. passwd: all authentication tokens updated successfully.
批量创建用户并设置密码为随机
方法1:
#!/bin/bash for n in `seq -w 10` do pass=`echo "$RANDOM"|md5sum|cut -c 1-8` useradd xcn$n&&\ echo "$pass" |passwd --stdin xcn$n echo -e "xcn$n\t $pass" >>/data/pass.log done
批量删除用户
#!/bin/bash for n in `seq 10` do userdel -r xcn$n &&\ done