In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to write Shell scripts to check the security status of the server". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Note: usually the security of the Linux server is mainly the check of the system users, the login server IP check, and the firewall status check!
1. You need to store the correct system user name in the / root/liu_shell/local_user.txt file and compare it!
two。 To determine whether the login IP starts with 192.168.1 and 192.168.2 IP is a normal IP!
3. Judge the status of iptables!
The code is as follows:
#! / usr/bin/python
# coding=utf-8
Import sys,os,re,socket
Host=str (socket.gethostname () .strip ())
Fuhao=os.linesep
Def user_panduan ():
File01=file ('/ etc/passwd')
Mmm= []
For xx in file01:
Mmm.append (re.split (':', xx) [0])
File01.close ()
File02=file ('/ root/liu_shell/new_user.txt','w')
For yy in mmm:
File02.write ('% s% s'% (yy,fuhao))
File02.close ()
F_local=file ('/ root/liu_shell/local_user.txt')
F_new=file ('/ root/liu_shell/new_user.txt')
Local_user= []
New_user= []
For line1 in f_local:
Line1=line1.strip ()
Local_user.append (line1)
For line2 in f_new:
Line2=line2.strip ()
New_user.append (line2)
F_local.close ()
F_new.close ()
If local_user==new_user:
Print 'host:%s user ok'% host
Else:
Cmd= "echo 'host:%s user error' | mail-s user_error 331095659@qq.com"% host
Os.system (cmd)
Def ip_panduan ():
Os.system ("last | awk'{print $3}'| grep-v [amurz] | grep-v ^ $| sort | uniq > / root/liu_shell/local_ip.txt")
F_ip=file ('/ root/liu_shell/local_ip.txt')
Local_ip= []
For line in f_ip:
Line=line.strip ()
Local_ip.append (line)
For aa in local_ip:
Kk=re.match ('192.168.1 | 192.168.2)
If kk:
Print 'host:%s ip ok'% host
Else:
Cmd= "echo 'host:%s ip error' | mail-s ip_error 331095659@qq.com"% host
Os.system (cmd)
Def iptables_panduan ():
Iptables_status=int (os.popen ("/ sbin/iptables-nL | grep-v ^ $| wc-l") .readline () .strip ())
If iptables_status==6:
Cmd= "echo 'host:%s iptables not runningbacks' | mail-s iptables 331095659@qq.com"% host
Os.system (cmd)
Else:
Print 'host:%s iptable running ok'% host
User_panduan ()
Ip_panduan ()
Iptables_panduan ()
This is the end of "how to write Shell scripts to check the security status of the server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un