linux服务器安全加固shell脚本代码
更新时间:2013年06月11日 15:05:34 作者:
有时候安装完服务器以后,需要一些安全设置,这段脚本就是为了安全加固所写,需要的朋友可以参考下
复制代码 代码如下:
#!/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 xfs
passwd -l news
passwd -l nscd
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 mailnull
passwd -l pcap
passwd -l mail
passwd -l shutdown
passwd -l halt
passwd -l uucp
passwd -l operator
passwd -l sync
passwd -l adm
passwd -l lp
# chattr /etc/passwd /etc/shadow
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
# 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
# system timeout 5 minite auto logout
echo "TMOUT=300" >>/etc/profile
# will system save history command list to 10
sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile
# enable /etc/profile go!
source /etc/profile
# add syncookie enable /etc/sysctl.conf
echo "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_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
您可能感兴趣的文章:
- 教你如何搭建一个安全的Linux服务器教程
- Linux VPS安全设置之一 修改SSH端口(CentOS/Debian)
- linux服务器基本安全配置手册
- Linux下Nginx安全证书ssl配置方法
- Linux SSH 安全策略 更改 SSH 端口
- 服务器安全狗Linux版软件安装使用说明
- linux服务器下PHPCMS v9 安全配置详解
- Linux 服务器安全配置
- 阿里云linux服务器上使用iptables设置安全策略的方法
- Linux服务器下nginx的安全配置详解
- linux Apache服务器系统安全设置与优化
- Red Hat Linux 安全设置方法
- centos 5.1下的安全设置(适合所有的linux版本)
- Linux VPS安全设置之二 禁用ROOT账户
- Linux SSH 安全策略 限制 IP 登录方法
- 安全检测Unix和Linux服务器安全设置入门精讲
- Linux下的Apache与PHP安全设置技巧
- Linux/CentOS服务器安全配置通用指南
相关文章
Linux下的自动化构建工具之make/makefile的用法详解
这篇文章主要为大家详细介绍了Linux下的自动化构建工具之make/makefile的区别与使用,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一下2022-10-10Linux中SELinux、Shell简介、touch命令的应用小结
SELinux(Security-Enhanced Linux)是美国国家安全局(NSA)对于强制访问控制的实现,是Linux历史上最杰出的新安全子系统,这篇文章主要介绍了Linux中SELinux、Shell简介、touch命令的应用知识总结,需要的朋友可以参考下2023-02-02在linux上定期执行命令、脚本(cron,crontab,anacron)
在linux下,如果想要在未来的某个时刻执行某个任务,并且在未来的每一个这样的时刻里都要执行这个任务。这篇文章主要介绍了在linux上定期执行命令、脚本(cron,crontab,anacron)的相关知识,需要的朋友可以参考下2018-07-07
最新评论