Centos7下批量创建用户,centos7创建用户警告时间7天,过期后


#!/bin/bash

#thisshellisusetobachusers

if[$#!=1];then

echo"Usage:root/batchusers"

elif[-f$1];then

forlinein`cat$1`

do

name=`echo$line|cut-d:-f1`

useradd-s/bin/bash$name

echo"123"|passwd--stdin$name

chage-d0-M90-W7-I2$name

echo"createduser:$name"

done

else

echo"inputfilenotfound"

fi

批量创建用户,同时为所有用户设置初始密码,并且通过chage命令设置用户密码过期时间为90天。警告时间7天,过期后过期后还能使用时间为2天。

使用方法,新建脚本batchuser.sh粘贴shell脚本,保存退出。

新建测试文件users,粘贴以下测试用户。通过命令

[plain]view plaincopy

print?

shbatchuser.shusers运行脚本即可批量创建用户。

运行结果:

[plain]view plaincopy

print?

ChangingpasswordforuserTarah.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Tarah

ChangingpasswordforuserJong.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Jong

ChangingpasswordforuserEmelda.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Emelda

ChangingpasswordforuserWilford.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Wilford

ChangingpasswordforuserCassy.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Cassy

ChangingpasswordforuserTrent.

passwd:allauthenticationtokensupdatedsuccessfully.

createduser:Trent

[plain]view plaincopy

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


相关内容

    暂无相关文章