您的位置:首页 > 运维架构 > Linux

Linux 基础优化与安全总结

2017-08-24 15:39 405 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息