linux系统优化脚本,linux系统优化脚本详解

#!/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值