1、关闭SELinux功能以及iptable
# vi /etc/selinux/config
SELINUX=enforcing ←改为SELINUX=disabled
# setenforce 0
# getenforce
Permissive
# /etc/init.d/iptables stop
# /etc/init.d/iptables status
iptables: Firewall is not running.2、设置运行级别
# runlevel ←查看当前运行模式
N 3
# vi /etc/inittab
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this) ←关机init 0,别设置成默认
# 1 - Single user mode ←单用户模式,救援模式使用
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking) ←多用户模式和模式3一样的,就是不能使用NFS
# 3 - Full multiuser mode ←多用户模式,最常用的模式
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this) ← 重启,也别设置成默认
#
id:3:initdefault: ← 数字就是默认使用那个模式
3、精简开机启动
#for n in `chkconfig --list |grep "3:on" |awk '{print $1;}'|egrep -v "crond|network|sshd|rsyslog|sysstat"`;do chkconfig $n off;done
# chkconfig --list |grep "3:on"
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off4、SSH远程登录
# vi /etc/ssh/sshd_config
Port 52113 ←修改端口为52113,今后登录需要IP:52113
PermitRootLogin no ←不允许root远程登录
PermitEmptyPasswords no ←不允许空密码登录
UseDNS no ← 不使用DNS解析, 你猜为啥子
GSSAPIAuthentication no ←该参数意思是在登录时,客户端会对服务端IP进行反向解析,如果没有相应记录,就要卡,登录就慢
# /etc/init.d/sshd reload ←平滑(优雅)重启,不会断开已经连接的用户
Reloading sshd: [ OK ]
5、sudo 授权,保证安全还能审计sudo命令记录,运维神器
# visudo
testuser ALL=(ALL) NOPASSWD:ALL
6、配置时间同步
# /usr/sbin/ntpdate time.nist.gov
# crontab -e
*/5 * * * * /usr/sbin/ntpdate time nist.gov &>/dev/null
# crontab -l
########time Server######
*/5 * * * * /usr/sbin/ntpdate time nist.gov &>/dev/null
# vi /etc/security/limits.conf ←顺便调整一下文件描述符
* - noflie 655358、定期清理邮件服务目录
# mkdir -p /server/scripts/
# echo "find /var/spool/postfix/maildrop/ -type f |xargs rm -f" >/server/scripts/del.file.sh
# cat /server/scripts/del.file.sh
find /var/spool/postfix/maildrop/ -type f |xargs rm -f
# crontab -e
# crontab -l
########time Server######
*/5 * * * * /usr/sbin/ntpdate time nist.gov &>/dev/null
00 00 * * * /bin/bash /server/scripts/del_file.sh &>/dev/null >> /var/spool/cron/root9、锁定系统关键文件
# chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
# lsattr /etc/passwd ←查看是否锁定文件
----i--------e- /etc/passwd
10、Grub加密
# /sbin/grub-md5-crypt
Password:
Retype password:
$1$cVeln$0ZBKaLOUry6gkykHykVXN1
# vi /etc/grub.conf ←在vi模式下:set nu 显示行号,必须添加hid和title之间,否则可能不生效
13 hiddenmenu
14 password --md5 $1$cVeln$0ZBKaLOUry6gkykHykVXN1
15 title CentOS (2.6.32-358.el6.x86_64)11、清空系统登录提示
# >/etc/issue
# >/etc/issue.net
12、配置yum更新源 ←以阿里云为例,国内还有163等其他yum仓库
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo可以看出,在初级优化中,有多项是针对系统安全设置,正如老男孩老师常说的一样:安全从小处和习惯做起!
参考资料:老男孩博客http://oldboy.blog.51cto.com/ |