现在的位置: 首页shell>正文
linux系统安全shell第二版
2011年05月13日 shell linux系统安全shell第二版已关闭评论 ⁄ 被围观 10,271 次+

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

  1. #!/bin/sh   
  2. # desc: setup linux system security   
  3. # author:coralzd   
  4. # powered by www.freebsdsystem.org   
  5. # version 0.1.2 written by 2011.05.03   
  6. #account setup   
  7.   
  8. passwd -l xfs   
  9. passwd -l news   
  10. passwd -l nscd   
  11. passwd -l dbus   
  12. passwd -l vcsa   
  13. passwd -l games   
  14. passwd -l nobody   
  15. passwd -l avahi   
  16. passwd -l haldaemon   
  17. passwd -l gopher   
  18. passwd -l ftp   
  19. passwd -l mailnull   
  20. passwd -l pcap   
  21. passwd -l mail   
  22. passwd -l shutdown   
  23. passwd -l halt   
  24. passwd -l uucp   
  25. passwd -l operator   
  26. passwd -l sync   
  27. passwd -l adm   
  28. passwd -l lp   
  29.   
  30. # chattr /etc/passwd /etc/shadow   
  31. chattr +i /etc/passwd   
  32. chattr +i /etc/shadow   
  33. chattr +i /etc/group   
  34. chattr +i /etc/gshadow   
  35. # add continue input failure 3 ,passwd unlock time 5 minite   
  36. 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   
  37. # system timeout 5 minite auto logout   
  38. echo "TMOUT=300" >>/etc/profile   
  39.   
  40. # will system save history command list to 10   
  41. sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile   
  42.   
  43. # enable /etc/profile go!   
  44. source /etc/profile   
  45.   
  46. # add syncookie enable /etc/sysctl.conf   
  47. echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf   
  48.   
  49. sysctl -p # exec sysctl.conf enable   
  50. # optimizer sshd_config   
  51.   
  52. sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config   
  53. sed -i  "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config   
  54.   
  55. # limit chmod important commands   
  56. chmod 700 /bin/ping   
  57. chmod 700 /usr/bin/finger   
  58. chmod 700 /usr/bin/who   
  59. chmod 700 /usr/bin/w   
  60. chmod 700 /usr/bin/locate   
  61. chmod 700 /usr/bin/whereis   
  62. chmod 700 /sbin/ifconfig   
  63. chmod 700 /usr/bin/pico   
  64. chmod 700 /bin/vi   
  65. chmod 700 /usr/bin/which   
  66. chmod 700 /usr/bin/gcc   
  67. chmod 700 /usr/bin/make   
  68. chmod 700 /bin/rpm   
  69.   
  70. # history security   
  71.   
  72. chattr +a /root/.bash_history   
  73. chattr +i /root/.bash_history   
  74.   
  75. # write important command md5   
  76. cat > list << "EOF" &&   
  77. /bin/ping   
  78. /bin/finger   
  79. /usr/bin/who   
  80. /usr/bin/w   
  81. /usr/bin/locate   
  82. /usr/bin/whereis   
  83. /sbin/ifconfig   
  84. /bin/pico   
  85. /bin/vi   
  86. /usr/bin/vim   
  87. /usr/bin/which   
  88. /usr/bin/gcc   
  89. /usr/bin/make   
  90. /bin/rpm   
  91. EOF   
  92.   
  93. for i in `cat list`   
  94. do  
  95.     if [ ! -x $i ];then  
  96.         echo "$i not found,no md5sum!"  
  97.     else  
  98.         md5sum $i >> /var/log/`hostname`.log   
  99.     fi   
  100. done   
  101. rm -f list  

security

本文地址:http://www.92csz.com/10/642.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.