《linux 批量删除用户的脚本公开课.docx》由会员分享,可在线阅读,更多相关《linux 批量删除用户的脚本公开课.docx(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、批量删除用户的脚本:# !/bin/bashfor num in1$(seq 1 20)douser=userSnumuserdel Suser# 删除用户userl2。rm -rf /home/Suser# 删除用户主目录rm /var/spool/mail/Suser# 删除用户邮件done执行脚本:执行脚本:rootftp shell# sh 2.shrootftp shell# cd /home/rootftp home# Is用户成功删除,主目录也全部删除:玳ehome# |成功八_八创建userl-20, userl的uid为601, user2的uid为602以此类推,将这20个
2、用户加 入到FTPgroup这个组里面,GID为600,设置用户密码为AAAbbb321。#/bin/bashgroupadd -g 600 FTPgroup#创建GID为6。的用户组,组名为FTPgroupfor num in S(seq 1 26)#定义num数组douid=S600+Snum#给心(1赋值.uid = 600 +numuser=userSnum#给心”赋值useradd -u Suid -g 600 Suser#创建用户echo AAAbbb3210 | passwd -stdin Suser#设置用户密码done执行脚本:Irootftp shell# sh 3.sh
3、Changing password for user passwd: all authentication Changing password for user passwd: all authentication Changing password for user查看/etc/group文件avahi-autoipd:x:102: gdm:x:42: named:x:25fl FTPgroup:x:600:可以看到成功建立FTPgroup用户组八_八userl.tokens updated successfully.user2.tokens updated successfully.use
4、r3.成功八_八查看/etc/passwd文件:user1:x: user2:x: user3:x: user4:x: user5:x: u s er 6: x: user7:x: user8:x: user9:x: userl0: userll: userl2: userl3: userl4: userl5: userl6: userl7: userl8: userl9: Jser20:601:600:602:606:603:600:604:600:605:606: 606:600: 607:606: 608:600:: 609:600: :610:600: :611:600: :612:6
5、00: :613:600: :614:600: :615:600: :616:600: :617:600: :618:600: :619:600: :620:600:/home/userl:/bin/bash /home/user2:/bin/bash /home/user3:/bin/bash /home/user4:/bin/bash /home/user5:/bin/bash /home/user6:/bin/bash /home/user7:/bin/bash /home/user8:/bin/bash /home/user9:/bin/bash :/home/userl0:/bin/bash :/home/userll:/bin/bash :/home/userl2:/bin/bash :/home/userl3:/bin/bash :/home/userl4:/bin/bash :/home/user15:/bin/bash :/home/userl6:/bin/bash :/home/userl7:/bin/bash :/home/userl8:/bin/bash :/home/userl9:/bin/bash :/home/user20:/bin/bash/pfr /nau/d1* K4I可以看到用户的UID与GID都符合要求八_八