README
  shell环境下运行脚本,根据需求选择相应的功能。

 List    \t\t  create the userlist 这一步是必须执行的,脚本会识别本地当前目录下的文件
Useradd \t\t useradd the user
Passwd \t\t set the password to userlist
Del \t\t deleate the user 删除用户之前必须要有需要删除用户的列表文件
Sudoers \t\t set the Sudoers
Exit \t\t quit the shell
 #!/bin/bash
########################################
#Author:qingbo.song #
#Date:2015.11. #
#E-mail:qingbo.song@apicloud.com #
#Comment: the system useradd #
#Path: /opt/shell/Linux_user_set.sh #
#Version:V 2.0 #
######################################## userfile="./userlist.txt"
Option_Echo()
{
echo -e "
######################################################
List \t\t create the userlist
Useradd \t\t useradd the user
Passwd \t\t set the password to userlist
Del \t\t deleate the user
Sudoers \t\t set the Sudoers
Exit \t\t quit the shell
######################################################"
} Welcome()
{
while [[ == ]]; do
echo "===============Welcome to use Linux_user_set.sh!==============="
echo "The shell to add the system user,and set the password to it! Please chose the option to run the program!"
#显示命令提示信息,调用Option_Echo函数
Option_Echo
#获取用户输入的信息
echo -n ":"
read option
if [[ -n "${option}" ]]; then #判断用户输入的信息不为空
if [[ "${option}" = "List" || "${option}" = "Useradd" || "${option}" = "Passwd" || "${option}" = "Del" || "${option}" = "Sudoers" || "${option}" = "Exit" ]]; then
if [[ "${option}" = "List" ]]; then
#创建用户列表函数调用
UserList
break
elif [[ "${option}" = "Useradd" ]]; then
#创建系统用户函数调用
UserAdd
break
elif [[ "${option}" = "Passwd" ]]; then
#设置用户密码函数调用
Passwd
break
elif [[ "${option}" = "Del" ]]; then
#sudoers函数调用
DelUser
break
elif [[ "${option}" = "Sudoers" ]]; then
Sudoers
break
elif [[ "${option}" = "Exit" ]]; then
#rm -fr ${userfile} #删除userlist.txt文件
echo "The shell is shutdown!"
rm -fr ${userfile}
exit
else
echo "Please input the ture option,Thank you!"
fi
else
echo "Please input the ture option,Thank you!"
fi
else
echo "The option is not NULL!Please input the ture option,Thank you!"
fi
done
} #创建用户列表
UserList()
{
echo "You will create a file of the user list,it's the ${userfile}!The format:"
echo -e "user01\nuser02"
echo "Please input the \"exit\" to quit"
#初始化userlist.txt
cat /dev/null > ${userfile}
while [[ $? == ]]; do
echo -n "Please input the user name:"
read name
if [[ -n "${name}" ]]; then #判断用户输入的信息是否非空
if [[ "${name}" = "exit" || "${name}" = "EXIT" || "${name}" = "Exit" ]]; then
Welcome
else
#将需要创建的用户添加到userlist.txt文件中
echo ${name} >> ${userfile}
echo "The user name \"${name}\" to save the file of ${userfile}!"
fi
else
echo "The name is not NULL!Please input the Ture user name,Thank you!!!"
fi
done
} #创建系统用户
UserAdd()
{
cat ${userfile} |grep -v "#"|while read LINE
do
echo "Create the user of ${LINE}!"
#-d 创建用户登录开始目录;-m 家目录不存在自动创建;-n 不创建相同名字的组;
#mkdir /users
useradd -d /home/${LINE} -m -n ${LINE} >> /dev/null >&
done Welcome
} #设置用户密码
Passwd()
{
ip=`ip addr|grep eth0|tail -|awk '{print $2}'|awk -F "/" '{print $1}'` #centos6.5获取
name=`hostname`
wdfile="./userpwdfile_${ip}_${name}.txt"
#重置user_password_list.txt
cat /dev/null > ${wdfile}
cat ${userfile} |grep -v "#"|while read LINE
do
echo "Produce the user of ${LINE} password:"
password=`</dev/urandom tr -dc '0123456789!@#$%{}<>=*&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | head -c24; echo ""`
echo "${LINE}:${password}" >> ${wdfile}
echo "${LINE}&&password save to the file ${wdfile}"
done
chpasswd < ${wdfile}
if [[ $? -eq ]]; then
echo "The user password to set success!"
else
echo "The user password to set ERROR!Please try again for yourself!"
fi
#返回Welcome界面
Welcome
} #批量删除user
DelUser()
{
echo "Now deleate the ${userfile} list of users:"
cat ${userfile} |grep -v "#"|while read LINE
do
echo "Deleate the user of ${LINE}!"
#-d 创建用户登录开始目录;-m 家目录不存在自动创建;-n 不创建相同名字的组;
userdel -r ${LINE} >> /dev/null >&
done Welcome
} #批量添加sudoers,请谨慎使用该功能
Sudoers()
{
echo "Now add the sudoers to /etc/sudoers:"
if [[ -f ${userfile} ]]; then
cat ${userfile}|grep -v "#"|while read LINE
do
echo "${LINE} ALL=(ALL) ALL" >> /etc/sudoers
echo "${LINE} 用户成功添加到sudoers中"
done
else
echo "${userfile}文件不存在!"
exit
fi Welcome
} #main 函数
Welcome

批量管理Linux系统用户

shell实现增加删除Linux系统用户脚本(密码为随机)的更多相关文章

  1. Linux系统用户/用户组/文件权限相关

    目录一.Linux系统用户/用户组权限相关二.Linux系统文件权限相关 一.Linux系统用户/用户组权限相关 .命令:usermod 用法:usermod [-agGus] user args ‘ ...

  2. linux系统用户管理(一)

    Linux系统用户管理1.用户管理*****2.Linux用户命令****3.用户创建的原理***4.密码管理***5.组命令管理**6.身份切换*****7.sudo提升权限***** 我们现在所使 ...

  3. 实验三 Linux系统用户管理及VIM配置

    项目 内容 这个作业属于哪个课程 班级课程的主页链接 这个作业的要求在哪里 作业要求链接接地址 学号-姓名 17041428-朱槐健 作业学习目标  1.学习Linux系统用户管理 2.学习vim使用 ...

  4. 实验三:Linux系统用户管理及VIM配置

    项目 内容 这个作业属于哪个课程 班级课程的主页链接 这个作业的要求在哪里 作业要求链接地址 学号-姓名 17043133-木腾飞 学习目标 1.学习Linux系统用户管理2.学习vim使用及配置 实 ...

  5. 重设windows10中的sub linux系统用户密码

    原文:重设windows10中的sub linux系统用户密码 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/haiyoung/article/detai ...

  6. 双系统删除Linux系统

    1.首先解决Linux的grub引导问题.电脑先安装了Windows10,然后又安装了Linux,grub直接覆盖了Windows的引导, 所以每次开机都是进入了Linux的grub引导,现在我们需要 ...

  7. Linux系统忘记管理员密码(CentOS、RHEL、Ubuntu)

    Linux系统忘记管理员密码(CentOS.RHEL.Ubuntu) 系统使用过程中,尤其是生产环境中.万一忘记管理员密码,该怎么办?是不是很绝望? 1.RHEL 7.0 重启主机进入引导界面键入e键 ...

  8. 忘记Linux root用户的密码怎么办?

    以前忘记windows密码的时候,要么用工具清除,要么重装系统.假如你忘记了linux系统的root密码,怎么办呢?是像windows一样用工具破解还是重装系统呢?哈哈,都不用.这方法很简单,现在做一 ...

  9. Linux 普通用户免密码切换到root用户

    Linux 普通用户免密码切换到root用户 # 添加用户 useradd user_name # 修改密码 echo "user_name@pwd" | passwd --std ...

随机推荐

  1. NATS_07:NATS之top工具监控以及测量调优工具

    概述 你可以使用 nats-top 来实现类似于 linux 中 top 命令的实时监控 nats 服务: 可以使用 nats 提供的工具来进行针对性的调优. 安装nats-top $ go get ...

  2. java基础-引用数据类型之一维数组(Array)

    java基础-引用数据类型之一维数组(Array) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数组的定义 1>.为什么需要数组 保存一个数据可以定义一个变量,如果要保 ...

  3. python---基础知识回顾(九)图形用户界面-------Tkinter

    前戏:老牌python GUI程序(Tkinter) import tkinter.messagebox as messagebox class Application(Frame): def __i ...

  4. Hi35xx 通用GPIO 使用篇(板子3G电源控制脚说明)

    在一个嵌入式系统中使用最多的莫过于 通用输入输出 GPIO口.看到论坛中经常有朋友问海思为什么没有提供GPIO驱动.其实不然. 在海思SDK  xxx/osdrv/tools/board_tools/ ...

  5. SVN不能提交代码

    Error: Some resources were not reverted. Attempted to lock an already-locked dir svn: Working copy ' ...

  6. TPL概要

    ReaderWriterLockSlim.读写锁,允许多个线程同时获取读锁,但同一时间只允许一个线程获得写锁,因此也称作共享-独占锁.只有等到对象被写入锁占用的时候,才会阻塞 Barrier .它允许 ...

  7. spring框架学习(五)整合JDBCTemplate

    1.导包 2.JdbcTemplate package cn.cnki.JdbcTemplate; import java.util.List; import org.junit.Test; impo ...

  8. python笔记之psutil模块

    收集教程 http://www.cnblogs.com/xiao1/p/6164204.html 实战教程 安装psutil模块 pip2 install psutil 实战代码 #encoding= ...

  9. [转]extern与头文件(*.h)的区别和联系

    用#include可以包含其他头文件中变量.函数的声明,为什么还要extern关键字? 如果我想引用一个全局变量或函数a,我只要直接在源文件中包含#include<xxx.h> (xxx. ...

  10. 【算法专题】后缀自动机SAM

    后缀自动机是用于识别子串的自动机. 学习推荐:陈立杰讲稿,本文记录重点部分和感性理解(论文语言比较严格). 刷题推荐:[后缀自动机初探],题目都来自BZOJ. [Right集合] 后缀自动机真正优于后 ...