Linux的系統安全設置Shell腳本

本腳本已經大量應用在某大型媒體網站體系中,加入了之前沒有想到的一些安全設置。使用方法將其複製,保存爲一個Shell文件,比如security.sh.將其上傳到Linux服務器上,執行sh security.sh,就可以使用該腳本了!

注意:腳本僅供參考,建議根據自己的實際需要來修改此腳本,不要盲目使用!
 

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章