linux服务器安全加固shell脚本

来源:互联网 发布:淘宝创建时间 编辑:程序博客网 时间:2024/05/21 15:03

#!/bin/sh    # desc: setup linux system security# author:coralzd# powered by www.xiaohuai.com# version 0.1.2 written by 2011.05.03#account setup    passwd -l xfspasswd -l newspasswd -l nscdpasswd -l dbuspasswd -l vcsapasswd -l gamespasswd -l nobodypasswd -l avahipasswd -l haldaemonpasswd -l gopherpasswd -l ftppasswd -l mailnullpasswd -l pcappasswd -l mailpasswd -l shutdownpasswd -l haltpasswd -l uucppasswd -l operatorpasswd -l syncpasswd -l admpasswd -l lp    # chattr /etc/passwd /etc/shadowchattr +i /etc/passwdchattr +i /etc/shadowchattr +i /etc/groupchattr +i /etc/gshadow# add continue input failure 3 ,passwd unlock time 5 minitesed -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# system timeout 5 minite auto logoutecho "TMOUT=300" >>/etc/profile    # will system save history command list to 10sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile    # enable /etc/profile go!source /etc/profile    # add syncookie enable /etc/sysctl.confecho "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf    sysctl -p # exec sysctl.conf enable# optimizer sshd_config    sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_configsed -i  "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config    # limit chmod important commandschmod 700 /bin/pingchmod 700 /usr/bin/fingerchmod 700 /usr/bin/whochmod 700 /usr/bin/wchmod 700 /usr/bin/locatechmod 700 /usr/bin/whereischmod 700 /sbin/ifconfigchmod 700 /usr/bin/picochmod 700 /bin/vichmod 700 /usr/bin/whichchmod 700 /usr/bin/gccchmod 700 /usr/bin/makechmod 700 /bin/rpm    # history security    chattr +a /root/.bash_historychattr +i /root/.bash_history    # write important command md5cat > list << "EOF" &&/bin/ping/bin/finger/usr/bin/who/usr/bin/w/usr/bin/locate/usr/bin/whereis/sbin/ifconfig/bin/pico/bin/vi/usr/bin/vim/usr/bin/which/usr/bin/gcc/usr/bin/make/bin/rpmEOF    for i in `cat list`do   if [ ! -x $i ];then   echo "$i not found,no md5sum!"  else   md5sum $i >> /var/log/`hostname`.log  fidonerm -f list

此shell脚本已经大量应用在某大型媒体网站体系中,关于脚本实现的加固内容,大家一看脚本就基本上能明白了,如果还不明白的话,那就GOOGLE+BAIDU吧! 如果还不知道的话,就问此脚本的作者吧!!哈哈

\