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. Docker简介和安装(一)

    Docker简介 Docker 是 Docker.Inc 公司开源的一个基于 LXC技术之上构建的Container容器引擎, 源代码托管在 GitHub 上, 基于Go语言并遵从Apache2.0协 ...

  2. JavaScript中的arguments详解

    1. arguments arguments不是真正的数组,它是一个实参对象,每个实参对象都包含以数字为索引的一组元素以及length属性. (function () { console.log(ar ...

  3. bzoj千题计划109:bzoj1019: [SHOI2008]汉诺塔

    http://www.lydsy.com/JudgeOnline/problem.php?id=1019 题目中问步骤数,没说最少 可以大胆猜测移动方案唯一 (真的是唯一但不会证) 设f[i][j] ...

  4. 【精选】Ubuntu 14.04 安装Nginx、php5-fpm、ThinkPHP5.0(已经测试上线)

    sudo apt-get update 安裝Nginx https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04 安裝完成後,Nginx的 ...

  5. typdef用法总结

    typdef是在计算机编程语言中用来为复杂的声明定义简单的别名用的 typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,在网上找了很多资料,结合自己遇到的各 ...

  6. 手机中的js事件

    // 手势事件 touchstart //当手指接触屏幕时触发 touchmove //当已经接触屏幕的手指开始移动后触发 touchend //当手指离开屏幕时触发 touchcancel // 触 ...

  7. 简易jQuery插件

    之前写过jQuery插件的笔记 如何用jQuery封装插件 我一直觉得前面讲了一大堆闭包和三种插件封装模式有点冗余,那篇笔记我直到记录到后面才发现这事情很简单,想来想去还是觉得网上的一些文章把事情搞复 ...

  8. [整理]内存重叠之memcpy、memmove

    函数原型: void *memcpy( void *dest, const void *src, size_t count ); void *memmove( void* dest, const vo ...

  9. springcloud中eureka集群unavailable-replicas

    unavailable-replicas 配置了集群,但是在注册中心显示另外的几个集群地址是不可用的: 1 首先需要再host中添加服务名映射,如果应映射了再看是否在yml中配置了prefer-ip- ...

  10. 基于消逝时间量的共识机制(POET)

    来自于Intel project:Hyperledger Sawtooth,目前版本 PoET 1.0 PoET 其实是属于Nakamoto consenus的一种,利用“可信执行环境”来提高当前解决 ...