shell脚本批量创建用户

微笑、不失礼 提交于 2020-01-02 16:28:28

shell脚本交互式批量创建用户:

#!/bin/sh
#Interactive bulk user creation
#num:Number of users created
#num>0
declare -i num
read -p 'Please enter the number of users to create:' num 
for i in `seq 1 $num`
do
        read -p "Please enter the username of the $i user you want to create:" username 
        useradd $username
        echo "Please give the user:$username a password!"
        passwd $username
done

shell脚本批量创建用户,用户密码初始化为:123456,第一次登录时强制修改密码

#!/bin/sh
#Create users in batches with an initial password of 123456, and force the password to be changed at the first login
#num:Number of users created 
#num>0
declare -i num
read -p 'Please enter the number of users to create:' num
for i in `seq 1 $num` 
do
        read -p "Please enter the username of the $i user you want to create:" username 
        useradd $username
        echo "The user:$username is initial password is 123456!"
        echo  123456 |passwd  --stdin  $username
        chage -d 0 $username
done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!