Chinaunix首页 | 论坛 | 博客
  • 博客访问: 299101
  • 博文数量: 103
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 858
  • 用 户 组: 普通用户
  • 注册时间: 2015-06-04 14:19
文章分类

全部博文(103)

文章存档

2016年(8)

2015年(95)

我的朋友

分类:

2015-06-08 14:52:33

原文地址:Linux系统优化 作者:sunsamson

#!/bin/bash
###----1、强制限制密码长度,保证密码强壮----###
vi /etc/login.defs
修改以下字段,强制限制最少的密码长度
PASS_MIN_LEN    12
###----2、注释掉不需要的用户和用户组----###
###注释以下用户###
#adm:x:3:4:adm:/var/adm:/sbin/nologin
#lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
#sync:x:5:0:sync:/sbin:/bin/sync
#shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
#halt:x:7:0:halt:/sbin:/sbin/halt
#news:x:9:13:news:/etc/news:
#uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
#operator:x:11:0:operator:/root:/sbin/nologin
#games:x:12:100:games:/usr/games:/sbin/nologin
#gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
#ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
###注释以下组###
#adm:x:4:root,adm,daemon
#lp:x:7:daemon,lp
#news:x:13:news
#uucp:x:14:uucp
#games:x:20:
#dip:x:40:
###----3、口令文件加不可更改属性,从而防止非授权用户获得权限----###
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow

###----4、禁止Ctrl Alt Delete重新启动机器命令----###
vi /etc/inittab
###注释以下参数###
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now
###然后重新设置/etc/rc.d/init.d/目录下所有文件的许可权限###
chmod -R 700 /etc/rc.d/init.d/*
###----5、限制其他用户su到root用户----###
echo "auth sufficient /lib/security/pam_rootok.so debug" >> /etc/pam.d/su
echo "auth required /lib/security/pam_wheel.so group=isd" >> /etc/pam.d/su

###----6、更改SSH端口,推荐改到60000以上----###
vi /etc/ssh/sshd_config
###修改SSH端口###
Port 65432
###注意修改这个端口之后,请记住修改Iptables里的允许端口###

###----7、关闭不必要的服务器----###
###停止服务###
#打印相关服务
service cups stop
chkconfig cups off
service cups-config-daemon stop
chkconfig cups-config-daemon off
#蓝牙设备相关
service dund stop
chkconfig dund off
service hidd stop
chkconfig hidd off
service bluetooth stop
chkconfig bluetooth off
service hcid stop
chkconfig hcid off
service sdpd stop
chkconfig sdpd off
service pand stop
chkconfig pand off
#ipv6防火墙
service ip6tables stop
chkconfig ip6tables off
#红外线通信
service irda stop
chkconfig irda off
service irattach stop
chkconfig irattach off
#isdn设备相关服务
service isdn stop
chkconfig isdn off
service capi stop
chkconfig capi off
#ibm硬件管理相关
service ibmasm stop
chkconfig ibmasm off
#自动挂载可移动存储器(服务器上一般不推荐)
service autofs stop
chkconfig autofs off
#Avahi 是 zeroconf 协议的实现。它可以在没有 DNS 服务的局域网里发现基于 zeroconf 协议的设备和服务.
service avahi-daemon stop
chkconfig avahi-daemon off
service avahi-dnsconfd stop
chkconfig avahi-dnsconfd off
#该服务进行硬件探测,并进行配置。绝大部分服务器都可以关闭它,仅仅在需要时启动
service kudzu stop
chkconfig kudzu off
#nfs相关服务,服务器建议关闭
service nfs stop
chkconfig nfs off
service nfslock stop
chkconfig nfslock off
service portmap stop
chkconfig portmap off
service rpcgssd stop
chkconfig rpcgssd off
service rpcidmapd stop
chkconfig rpcidmapd off
service rpcsvcgssd stop
chkconfig rpcsvcgssd off
#提供智能卡(和嵌入在信用卡,识别卡里的小芯片一样大小)和智能卡读卡器支持
service pcscd stop
chkconfig pcscd off
service pcmcia stop
chkconfig pcmcia off
#邮件服务,建议关闭
service sendmail stop
chkconfig sendmail off
#在服务器准备进入生产环境时,建议关闭yum-update服务
service yum-updatesd stop
chkconfig yum-updatesd off
###----8、TCP/IP网络参数进行调整,加强抗SYN Flood能力----###
echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.conf
sysctl -p
###----9、修改命令history记录----###
sed -i 's#HISTSIZE=1000#HISTSIZE=1#' /etc/profile
rm -f /root/.bash_history
rm -f /root/.mysql_history
ln -s /dev/null /root/.bash_history
ln -s /dev/null /root/.mysql_history
###----10、禁用IPV6功能(reboot生效)----###
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
 
 
阅读(533) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~