Linux系统安全Shell第二版

字体大小: 中小 标准 ->行高大小: 标准

本Linux Shell脚本是第二次更新,已经大量应用在某大型媒体网站体系中,加入了之前没有想到的一些安全设置。使用方法将其复制,保存为一个shell文件,比如security.sh.将其上传到linux服务器上,执行sh security.sh,就可以使用该脚本了! 

  1. #!/bin/sh # desc: setup linux system security 
  2. # author:coralzd # powered by www.freebsdsystem.org 
  3. # version 0.1.2 written by 2011.05.03 #account setup 
  4.  passwd -l xfs 
  5. passwd -l news passwd -l nscd 
  6. passwd -l dbus passwd -l vcsa 
  7. passwd -l games passwd -l nobody 
  8. passwd -l avahi passwd -l haldaemon 
  9. passwd -l gopher passwd -l ftp 
  10. passwd -l mailnull passwd -l pcap 
  11. passwd -l mail passwd -l shutdown 
  12. passwd -l halt passwd -l uucp 
  13. passwd -l operator passwd -l sync 
  14. passwd -l adm passwd -l lp 
  15.  # chattr /etc/passwd /etc/shadow 
  16. chattr +i /etc/passwd chattr +i /etc/shadow 
  17. chattr +i /etc/group chattr +i /etc/gshadow 
  18. # add continue input failure 3 ,passwd unlock time 5 minite sed -i 's#auth        required      pam_env.so#auth        required      pam_env.so\nauth       required       pam_tally.so  onerr=fail deny=3 unlock_time=300\nauth           required     /lib/security/$ISA/pam_tally.so onerr=fail deny=3 unlock_time=300#' /etc/pam.d/system-auth 
  19. # system timeout 5 minite auto logout echo "TMOUT=300" >>/etc/profile 
  20.  # will system save history command list to 10 
  21. sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile  
  22. # enable /etc/profile go! source /etc/profile 
  23.  # add syncookie enable /etc/sysctl.conf 
  24. echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf  
  25. sysctl -p # exec sysctl.conf enable # optimizer sshd_config 
  26.  sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config 
  27. sed -i  "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config  
  28. # limit chmod important commands chmod 700 /bin/ping 
  29. chmod 700 /usr/bin/finger chmod 700 /usr/bin/who 
  30. chmod 700 /usr/bin/w chmod 700 /usr/bin/locate 
  31. chmod 700 /usr/bin/whereis chmod 700 /sbin/ifconfig 
  32. chmod 700 /usr/bin/pico chmod 700 /bin/vi 
  33. chmod 700 /usr/bin/which chmod 700 /usr/bin/gcc 
  34. chmod 700 /usr/bin/make chmod 700 /bin/rpm 
  35.  # history security 
  36.  chattr +a /root/.bash_history 
  37. chattr +i /root/.bash_history  
  38. # write important command md5 cat > list << "EOF" && 
  39. /bin/ping /bin/finger 
  40. /usr/bin/who /usr/bin/w 
  41. /usr/bin/locate /usr/bin/whereis 
  42. /sbin/ifconfig /bin/pico 
  43. /bin/vi /usr/bin/vim 
  44. /usr/bin/which /usr/bin/gcc 
  45. /usr/bin/make /bin/rpm 
  46. EOF  
  47. for i in `cat list` do 
  48.    if [ ! -x $i ];then    echo "$i not found,no md5sum!" 
  49.   else    md5sum $i >> /var/log/`hostname`.log 
  50.   fi done 
  51. rm -f list 

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/60313.html