linux检测root权限shell脚本升级版

发布时间:2020-04-05编辑:脚本学堂
linux下用于检测root权限的shell脚本,用shell检测用户是否有root权限,比较方便,用来研究shell编程以及awk等命令的用法也不错,需要的朋友参考下。

一个检测root权限的shell/ target=_blank class=infotextkey>shell脚本,代码:
 

复制代码 代码示例:

#!/bin/bash
#chk_root.sh
#

echo test your computer is or not safety.
sleep 1
root_num=`linuxjishu/13830.html target=_blank class=infotextkey>awk -F: '{print $3}' /etc/passwd|grep "b0b"|wc -l`
case $root_num in
0)
echo your system dont have root.
;;
1)
echo your system is safety.
;;
*)
echo your system mybe cracked.
awk -F: '{print $1,$3}' /etc/passwd|grep "b0b" >> hack1
cat hack1|awk '{print $1}'|grep -v "root" >> hack2
for hacker in `cat hack2`
do
read -p "$hacker mybe created by hacker. Do you want to kill it ?" answer
case $answer in
y)
userdel  $hacker
echo $hacker is killed.
;;
yes)
userdel  $hacker
echo $hacker is killed.
;;
n)
;;
no)
;;
*)
;;
esac
done
esac
rm -f hack*