1,不用root登錄管理系統,而以普通用戶身份登錄,通過sudo授權管理。
2、更改默認的遠程連接SSH服務器端口,禁止root 用戶遠程連接,甚至更改SSH服務只監聽內網IP。
3、定時自動更新服務器時間,使其祕互聯網時間同步。
4、配置yum更新源,從國內更新源下載安裝軟件包。
5、關閉SELinx及iptables
sed -i 's/SELINUX=enforcing/SELINUX=disabled' /etc/selinux/config
6、調整文件描述符的數量,進程及文件的打開都會消耗文件描述符數量。
查看 ulimit -n
方法1、
vim /etc/security/limits.conf * - nofile 65535
配置完成後,重新登錄纔可以生效。
方法2、
cat >>/etc/rc.local<<EOF ulimit -HSn 65535 ulimit -s 65535 EOF
7、定時自動清理郵件臨時目錄垃圾,防止磁盤的innodes數被小文件佔滿(centos5和centos6要清的目錄不同)
手動清理的方法:
find /var/spool/clientmqueue -type f |xargs rm -f (centos5 的 sendmail) find /var/spool/postfix/maildrop/ -type f |xargs rm -f (centos 6的postfix)
定時清理的方法:
echo "find /var/spool/postfix/maildrop/ -type f |xargs rm -f">>/server/scripts/del_file.sh echo "00 00 * * * /bin/sh /server/scripts/del_file.sh>dev/null 2&1">>/var/spool/cron/root crontab -l df -i
8、精簡併保留必要的開機自動服務(如:crond、sshd、network、rsyslog、sysstat)。
9、Linux內核參數優化/etc/sysctl.conf,執行sysctl -p 生效。
10、更改字符集爲“zh_CN.UTF-8”,使其支持中文。
11、鎖定關鍵系統文件,如/etc/passwd、/etc/group、/etc/inittab,處理以上內容後把chattr、isattr改名爲yenokia並轉移。
chattr +i /etc/passwd /etc/shadow /etc/group /etc/inttab [root@access01 ~]# lsattr /etc/passwd ----i--------e- /etc/passwd chattr -i /etc/passwd /etc/shadow /etc/group /etc/inttab mv /usr/bin/chattr usr/bin/yenokia yenokia +i /etc/passwd /etc/shadow /etc/group /etc/inttab
12、清空/etc/issue、/etc/issue.net,去除系統及內核版本登錄前的屏幕顯示。
cat /etc/issue
cat /etc/issue.net
> /etc/issue > /etc/issue.net
13、清除多餘的系統虛擬用戶賬號。
14、爲grub引導菜單加密碼。
[root@access01 ~]# /sbin/grub-md5-crypt Password: Retype password: $1$tzK2T/$o0ULSzkPYAuNn6YX6nSKR/ [root@access01 ~]#vim /etc/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You do not have a /boot partition. This means that # all kernel and initrd paths are relative to /, eg. # root (hd0,1) # kernel /boot/vmlinuz-version ro root=/dev/xvda2 # initrd /boot/initrd-[generic-]version.img #boot=/dev/xvda default=0 timeout=5 splashimage=(hd0,1)/boot/grub/splash.xpm.gz hiddenmenu password --md5 $1$tzK2T/$o0ULSzkPYAuNn6YX6nSKR #注意:password 要加在splashimage 和title之間,否則可能無法生效 title CentOS (2.6.32-642.3.1.el6.x86_64) root (hd0,1) kernel /boot/vmlinuz-2.6.32-642.3.1.el6.x86_64 ro root=UUID=1a1ce4de-e56a-4e1f-864d-31b7d9dfb547 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYS FONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /boot/initramfs-2.6.32-642.3.1.el6.x86_64.img title CentOS (2.6.32-431.el6.x86_64) root (hd0,1) kernel /boot/vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=1a1ce4de-e56a-4e1f-864d-31b7d9dfb547 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT =latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /boot/initramfs-2.6.32-431.el6.x86_64.img
15、禁止ping
在默認dorp情況下,允許10.0.0.0/24 網段ping。
iptables -t filter -I INPUT -p icmp --icmp-type 8 -i eth0 -s 10.0.0.0/24 -j ACCEPT
16、升級具有典型漏洞的軟件版本。
查看軟件的版本號
rpm -qa openssh openssl bash
升級
yum install openssh openssl bash -y