linux 权限测试,linux下检测root权限的shell脚本
個(gè)人心血來(lái)潮時(shí)寫(xiě)的一個(gè)腳本,比較粗糙,功能也很簡(jiǎn)單,大家有興趣的可以拿去改改。
本腳本之爭(zhēng)對(duì)系統(tǒng)中UID為0的用戶(hù)
#!/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文件中第三個(gè)域的字段,并grep以“0”開(kāi)頭的(意思是UID是0的用戶(hù)),然后計(jì)算行數(shù)(3行代表有3個(gè)UID為0的用戶(hù),包括root),最終賦值給root_num.
if [ $root_num -eq 1 ];then? #如果$root_num的值為1,表示只有一個(gè)root用戶(hù)
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中的第三個(gè)域(UID)和第一個(gè)域(用戶(hù)名),并且grep以“0”開(kāi)頭的行,輸出到hack1的文件中
cat hack1|awk '{print $2}'>>hack????? #查看hack1文件的內(nèi)容,并打印出第二個(gè)域的內(nèi)容,輸出到hack文件中
for number in `cat hack`???? #查看hack的內(nèi)容,并循環(huán)賦值給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文件
有興趣的可以試試。功能很簡(jiǎn)單,只為娛樂(lè)娛樂(lè)。
總結(jié)
以上是生活随笔為你收集整理的linux 权限测试,linux下检测root权限的shell脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 华山松和乔松的区别?
- 下一篇: linux core 永久生效,【调试】