教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 linux系统安全shell第二版(超强大)

linux系统安全shell第二版(超强大)

发布时间:2014-09-30   编辑:jiaochengji.com
介绍:本脚本是第二次更新,已经大量应用在某大型媒体网站体系中,加入了之前没有想到的一些安全设置。使用方法:保存为一个shell文件,比如security.sh.将其上传到linux服务器上,执行sh security.sh...

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

复制代码 代码如下:
#!/bin/sh
# desc: setup linux system security
# author:coralzd
# powered by www.freebsdsystem.org
# version 0.1.2 written by 2011.05.03
#account setup
 
passwd -l xfsx
passwd -l news
passwd -l nscdx
passwd -l dbus
passwd -l vcsa
passwd -l games
passwd -l nobody
passwd -l avahi
passwd -l haldaemon
passwd -l gopher
passwd -l ftp
passwd -l mailnullx
passwd -l pcapx
passwd -l mail
passwd -l shutdownx
passwd -l haltx
passwd -l uucp
passwd -l operator
passwd -l sync
passwd -l adm
passwd -l lpx
 
# chattr /etc/passwd /etc/shadow
chattr +i /etc/passwdx
chattr +i /etc/shadowx
chattr +i /etc/groupx
chattr +i /etc/gshadowx
# add continue input failure 3 ,passwd unlock time 5 minite
sed -i 's#authrequired  pam_env.so#authrequired  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 logout
echo "TMOUT=300" >>/etc/profilex
 
# will system save history command list to 10
sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile
 
# enable /etc/profile go!
source /etc/profilex
 
# add syncookie enable /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.confx
 
sysctl -p # exec sysctl.conf enable
# optimizer sshd_configx
 
sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config
sed -i  "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
 
# limit chmod important commands
chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm
 
# history security
 
chattr +a /root/.bash_history
chattr +i /root/.bash_history
 
# write important command md5
cat > 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/rpm
EOF
 
for i in `cat list`
do
   if [ ! -x $i ];then
   echo "$i not found,no md5sum!"
  else
   md5sum $i >> /var/log/`hostname`.log
  fi
done
rm -f list

本文转自:http://coralzd.blog.51cto.com/90341/564887

您可能感兴趣的文章:
inux shell初级入门教程
linux系统安全shell第二版(超强大)
理解linux中的bash和profile
solaris10默认shell修改与设置
安装python还要安装什么
Linux系统分区详解
【跟着我们学Golang】Go语言全平台安装
python shell是什么
更改linux用户登录shell的方法
将PHP作为Shell脚本语言使用

[关闭]
~ ~