Centos7下批量创建用户
Posted owen-li
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7下批量创建用户相关的知识,希望对你有一定的参考价值。
#!/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,粘贴以下测试用户。通过命令
sh batchuser.sh users 运行脚本即可批量创建用户。
运行结果:
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
测试用户:
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
以上是关于Centos7下批量创建用户的主要内容,如果未能解决你的问题,请参考以下文章