Centos7下批量创建用户
时间:2017-04-05 22:41 来源:linux.it.net.cn 作者:IT
-
#!/bin/bash
-
#this shell is use to bachusers
-
if [ $# != 1 ];then
-
echo "Usage:root/batchusers"
-
elif [ -f $1 ];then
-
for line in `cat $1`
-
do
-
name=`echo $line | cut -d : -f1`
-
useradd -s /bin/bash $name
-
echo "123" | passwd --stdin $name
-
chage -d 0 -M 90 -W 7 -I 2 $name
-
echo "created user: $name"
-
done
-
else
-
echo "input file not found"
-
fi
批量创建用户,同时为所有用户设置初始密码,并且通过chage命令设置用户密码过期时间为90天。警告时间7天,过期后过期后还能使用时间为2天。
使用方法,新建脚本batchuser.sh粘贴shell脚本,保存退出。
新建测试文件users,粘贴以下测试用户。通过命令
[plain] view plain copy
print?
-
sh batchuser.sh users 运行脚本即可批量创建用户。
运行结果:
[plain] view plain copy
print?
-
Changing password for user Tarah.
-
passwd: all authentication tokens updated successfully.
-
created user: Tarah
-
Changing password for user Jong.
-
passwd: all authentication tokens updated successfully.
-
created user: Jong
-
Changing password for user Emelda.
-
passwd: all authentication tokens updated successfully.
-
created user: Emelda
-
Changing password for user Wilford.
-
passwd: all authentication tokens updated successfully.
-
created user: Wilford
-
Changing password for user Cassy.
-
passwd: all authentication tokens updated successfully.
-
created user: Cassy
-
Changing password for user Trent.
-
passwd: all authentication tokens updated successfully.
-
created user: Trent
[plain] view plain copy
print?
-
测试用户:
-
Betsey:Werts:60:1
-
Henriette:Balla:30:1
-
Julieann:Hopps:30:2
-
Conrad:Menz:60:1
-
Annabell:Cho:90:1
-
Allyn:Kenley:60:1
-
Ceola:Jacquez:60:1
-
Rebecca:Fabry:60:1
-
Philip:Bamber:90:1
-
Nguyet:Dills:30:3
-
Christopher:Reeser:60:1
-
Christin:Racicot:30:1
-
Nelda:Moczygemba:30:3
-
Allyson:Bourland:30:1
-
Lonna:Harryman:30:1
-
Carmine:Stivers:30:2
-
Kayce:Shafer:30:2
-
Pedro:Woll:60:3
-
Page:Bonilla:30:1
-
Grady:Waugh:60:3
-
Elsa:Casazza:60:3
-
Dorothy:Meshell:30:3
-
Benton:Hoefler:60:2
-
Trista:Talley:30:2
-
Eartha:Jacks:60:1
-
Mayra:Louie:60:2
-
Edmundo:Goodsell:90:1
-
Tamika:Allred:90:1
-
Candance:Earwood:60:2
-
Danae:Corrado:30:3
-
Mozell:Galan:60:2
-
Herman:Younts:60:2
-
Laine:Womac:30:3
-
Kanisha:Hulin:30:1
-
Robyn:Alcantara:30:1
-
Derrick:Fleenor:30:2
-
Sommer:Herz:90:1
-
Monika:Drakeford:30:2
-
Valda:Harrel:60:2
-
Hilde:Ruder:30:3
-
Willow:Feltman:30:1
-
Reiko:Kolar:90:2
-
Ismael:Frisby:90:3
-
Iris:Countess:30:3
-
Tarah:Buster:30:2
-
Jong:Cazares:30:2
-
Emelda:Sundquist:60:1
-
Wilford:Hankey:60:3
-
Cassy:Rundle:60:1
-
Trent:Grana:60:3
-
(责任编辑:IT)
批量创建用户,同时为所有用户设置初始密码,并且通过chage命令设置用户密码过期时间为90天。警告时间7天,过期后过期后还能使用时间为2天。 使用方法,新建脚本batchuser.sh粘贴shell脚本,保存退出。 新建测试文件users,粘贴以下测试用户。通过命令
[plain] view plain copy
运行结果:
[plain] view plain copy
[plain] view plain copy
(责任编辑:IT) |