linux下检测root权限的shell脚本
2011-01-21 16:43
393 查看
个人心血来潮时写的一个脚本,比较粗糙,功能也很简单,大家有兴趣的可以拿去改改。
本脚本之争对系统中UID为0的用户
#!/bin/bash #大家都知道
echo test my computer is or not safety #显示“ test my computer is or not safety ”
root_num=`awk -F: '{print $3}' /etc/passwd|grep "^0"|wc -l` #以“:”为分隔符,打印出/etc/passwd文件中第三个域的字段,并grep以“0”开头的(意思是UID是0的用户),然后计算行数(3行代表有3个UID为0的用户,包括root),最终赋值给root_num.
if [ $root_num -eq 1 ];then #如果$root_num的值为1,表示只有一个root用户
echo your computer is safety #显示“ your computer is safety ”
else #否则
awk -F: '{print $3,$1}' /etc/passwd|grep "^0"|grep -v "root" >> hack1 #打印/etc/passwd中的第三个域(UID)和第一个域(用户名),并且grep以“0”开头的行,输出到hack1的文件中
cat hack1|awk '{print $2}'>>hack #查看hack1文件的内容,并打印出第二个域的内容,输出到hack文件中
for number in `cat hack` #查看hack的内容,并循环赋值给number
do
echo $number mybe created by hacker. #显示“ xxx mybe created by hacker.”
read -p "are you want to delete it? y or n :" answer #显示“are you want to delete it? y or n :“
if [ $answer = "y" ] #如果回答是”y“
then
userdel -r $numeber #删除xxx
echo $number is delete. #显示”xxx is dele“
if [ $answer = "yes"] #如果回答是”yes“
then
userdel -r $number
echo $number is delete.
fi
fi
done
fi
rm -f hack* #删除hack和hack1文件
有兴趣的可以试试。功能很简单,只为娱乐娱乐。
本脚本之争对系统中UID为0的用户
#!/bin/bash #大家都知道
echo test my computer is or not safety #显示“ test my computer is or not safety ”
root_num=`awk -F: '{print $3}' /etc/passwd|grep "^0"|wc -l` #以“:”为分隔符,打印出/etc/passwd文件中第三个域的字段,并grep以“0”开头的(意思是UID是0的用户),然后计算行数(3行代表有3个UID为0的用户,包括root),最终赋值给root_num.
if [ $root_num -eq 1 ];then #如果$root_num的值为1,表示只有一个root用户
echo your computer is safety #显示“ your computer is safety ”
else #否则
awk -F: '{print $3,$1}' /etc/passwd|grep "^0"|grep -v "root" >> hack1 #打印/etc/passwd中的第三个域(UID)和第一个域(用户名),并且grep以“0”开头的行,输出到hack1的文件中
cat hack1|awk '{print $2}'>>hack #查看hack1文件的内容,并打印出第二个域的内容,输出到hack文件中
for number in `cat hack` #查看hack的内容,并循环赋值给number
do
echo $number mybe created by hacker. #显示“ xxx mybe created by hacker.”
read -p "are you want to delete it? y or n :" answer #显示“are you want to delete it? y or n :“
if [ $answer = "y" ] #如果回答是”y“
then
userdel -r $numeber #删除xxx
echo $number is delete. #显示”xxx is dele“
if [ $answer = "yes"] #如果回答是”yes“
then
userdel -r $number
echo $number is delete.
fi
fi
done
fi
rm -f hack* #删除hack和hack1文件
有兴趣的可以试试。功能很简单,只为娱乐娱乐。
相关文章推荐
- linux下检测root权限的shell脚本(2)
- shell写的检测linux系统硬件信息的脚本
- linux下如何自动检测并重新启动一个死掉的进程,然后再把它杀死:)(shell脚本实现)
- shell脚本实现linux系统文件完整性检测
- shell脚本实现linux系统文件完整性检测
- linux下利用shell脚本自动检测服务状态并自动恢复服务
- linux下如何自动检测并重新启动一个死掉的进程(shell脚本实现)
- Linux的shell脚本的语句,函数,检测服务,启动脚本的练习
- linux下shell脚本的使用——安装madplay播放器,sed函数详解
- linux和windows下的自动ftp脚本(shell bat)
- Linux的系统安全设置Shell脚本
- Linux基本功十一:shell脚本执行及交互
- 这篇文章主要介绍了Linux中执行shell脚本的4种方法总结
- 检测网段IP使用情况的shell脚本
- linux中Shell脚本应用(二)
- Linux_Shell 服务器互通脚本, 第一次通信 自动记入 know_hosts
- linux C程序中获取shell脚本输出(如获取system命令输出)
- Linux系统shell脚本判断变量文件目录+l脚本的字符串截取(转)
- linux边学边记---Shell脚本的追踪与debug
- Linux 基础命令(六)—— SHELL脚本编程基础