shell实现增加删除Linux系统用户脚本(密码为随机)
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系统用户脚本(密码为随机)的更多相关文章
- Linux系统用户/用户组/文件权限相关
		目录一.Linux系统用户/用户组权限相关二.Linux系统文件权限相关 一.Linux系统用户/用户组权限相关 .命令:usermod 用法:usermod [-agGus] user args ‘ ... 
- linux系统用户管理(一)
		Linux系统用户管理1.用户管理*****2.Linux用户命令****3.用户创建的原理***4.密码管理***5.组命令管理**6.身份切换*****7.sudo提升权限***** 我们现在所使 ... 
- 实验三 Linux系统用户管理及VIM配置
		项目 内容 这个作业属于哪个课程 班级课程的主页链接 这个作业的要求在哪里 作业要求链接接地址 学号-姓名 17041428-朱槐健 作业学习目标 1.学习Linux系统用户管理 2.学习vim使用 ... 
- 实验三:Linux系统用户管理及VIM配置
		项目 内容 这个作业属于哪个课程 班级课程的主页链接 这个作业的要求在哪里 作业要求链接地址 学号-姓名 17043133-木腾飞 学习目标 1.学习Linux系统用户管理2.学习vim使用及配置 实 ... 
- 重设windows10中的sub linux系统用户密码
		原文:重设windows10中的sub linux系统用户密码 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/haiyoung/article/detai ... 
- 双系统删除Linux系统
		1.首先解决Linux的grub引导问题.电脑先安装了Windows10,然后又安装了Linux,grub直接覆盖了Windows的引导, 所以每次开机都是进入了Linux的grub引导,现在我们需要 ... 
- Linux系统忘记管理员密码(CentOS、RHEL、Ubuntu)
		Linux系统忘记管理员密码(CentOS.RHEL.Ubuntu) 系统使用过程中,尤其是生产环境中.万一忘记管理员密码,该怎么办?是不是很绝望? 1.RHEL 7.0 重启主机进入引导界面键入e键 ... 
- 忘记Linux root用户的密码怎么办?
		以前忘记windows密码的时候,要么用工具清除,要么重装系统.假如你忘记了linux系统的root密码,怎么办呢?是像windows一样用工具破解还是重装系统呢?哈哈,都不用.这方法很简单,现在做一 ... 
- Linux 普通用户免密码切换到root用户
		Linux 普通用户免密码切换到root用户 # 添加用户 useradd user_name # 修改密码 echo "user_name@pwd" | passwd --std ... 
随机推荐
- P2306 被yyh虐的mzc
			P2306 被yyh虐的mzc 容量为 \(V\), 有 \(n\) 件物品, 反正直接背包绝对超时 , 每个有重量和价值 \(a_{i}, b_{i}(a_{i}, b_{i} <= 10)\ ... 
- Java基础-IO流对象之打印流(PrintStream与PrintWriter)
			Java基础-IO流对象之打印流(PrintStream与PrintWriter) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.打印流的特性 打印对象有两个,即字节打印流(P ... 
- 应用jfinal时要注意区分Db.query和Db.find
			jfinal有一个特别好的地方,sql查询的时候可以直接查record.但是要注意query和find的区别. query返回的是List<object>,find返回的才是List< ... 
- Calculus on Computational Graphs: Backpropagation
			Calculus on Computational Graphs: Backpropagation Introduction Backpropagation is the key algorithm ... 
- 使用spring的监听器来完成系统超级管理员的注册
			1.注入 2“util类 package com.liveyc.mgrsite.util; import org.springframework.beans.factory.annotation.Au ... 
- Python概念-Attr系列(林海峰教的)
			这个Attr系列是egon老师自创的,个人还是可以接受这种文化底蕴的,所以直接拿来用,也是毫无违和感的 所谓Attr系列,其实是__setattr__,__delattr__,__getattr__ ... 
- php strcmp()函数
			<? $str = "LAMP"; $str1 = "LAMPBrother"; $strc = strcmp($str,$str1); switch ( ... 
- Ubuntu: HDF5报错: HDF5 header version与HDF5 library不匹配
			今天在执行一个用到hdf5的python脚本时,遇到如下错误 Warning! ***HDF5 library version mismatched error*** The HDF5 header ... 
- http Get和Post请求方式
			string postURL ="http://xxxxx.ashx"; List<string> paramName = new List<string&g ... 
- ORB_SLAM2 源码阅读 ORB_SLAM2::Initializer
			ORB_SLAM2::Initializer 用于单目情况下的初始化. Initializer 的构造函数中传入第一张影像,这张影像被称作 reference frame(rFrame).在获得第二张 ... 
