linux(centos)系统安装后必做的十三点基础安全优化(安装后必备)
2016-09-30 00:00
721 查看
系统安装后不要急于部署,先把下面十三条基础优化做了(安装后必备)
重启ssh服务
service sshd restart 或 /etc/init.d/sshd restart
1. 不用root 登录,添加普通用户,用sudo授权管理
[root@centos6 ~]#useradd liuwei 添加用户 [root@centos6 ~]# vi /etc/sudoers 在第98行下面加入 root ALL=(ALL) ALL liuwei ALL=(ALL) /bin/ls ,/bin/cat //这个是给liuwei这个用户 添加 /bin/ls ,/bin/cat 这两个命令的执行权限
2.更改默认的远程连接SSH服务端口和禁止root远程登录
[root@centos6 ~]# vi /etc/ssh/sshd_config # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options change a # default value. #下面这是把22端口更改52113 Port 52113 #这是不允许远程登录 PermitRootLogin no #这个不是不允许空密码 PermitEmptyPasswords no #不用DNS UseDNS no GSSAPIAuthentication no
重启ssh服务
service sshd restart 或 /etc/init.d/sshd restart
3.定时更新服务器时间
#confab -e 进入cronta编辑模式,使用方法同vi 输入 0 23 * * * ntpdate asia.pool.ntp.org >> /var/log/ntpdate.log 保存退出 这样就完成了你的系统到每天23:00去asia.pool.ntp.org 同步时间,并将同步的日志放到 /var/log/ntpdate.log 三、定时同步时间(在/etc/crontab中添加) * * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1
4.配置yum更新源,从国内更新源下载安装rpm包
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo[/code]5.关闭selinux关闭iptables(工作场景有wan ip 一般要开,高并发除外)
修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可(注意:生产环境中一般不能随便重启机器) setenforce 更改selinux状态 setenforce 0 #设置SELinux 成为permissive模式 setenforce 1 设置SELinux 成为enforcing模式 getenforce 也可以用这个命令检查 /etc/init.d/iptables status 会得到一系列信息,说明防火墙开着。 /etc/init.d/iptables stop 关闭防火墙 service iptables restart 重启iptables /etc/init.d/iptables restart 重启iptables 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2. 即时生效,重启后失效: 开启:service iptables start 关闭:service iptables stop6.调整描述符的数量,进程及文件打开都会消耗描述符
[root@centos6 ~]# ulimit –n 查看描述符数量 65535 怎么调整 vim /etc/security/limits.conf 把下面一句加到文件的最后一行 * - nofile 65535 或者: ech0 '* - nofile 65535' >> /etc/security/limits.conf7.定时清理 /var/spool/clientmquene/目录垃圾文件,防止inodes节点占满
8.精简开机启动服务(crod,sshd,network,rsyslog)
for name in ‘chkconfig --list | grep –vE “crond|sshd|network|rsyslog”|awk ‘{print $1}’’; do chkconfig &name off;done9.linux 内核参数优化 /etc/sysctl.conf,执行sysctl –p 生效
首先打开/etc/sysctl.conf文件,查看如下两行的设置值,这里是: kernel.shmall = 2097152 kernel.shmmax = 4294967295 如果系统默认的配置比这里给出的值大,就不要修改原有配置。 同时在/etc/sysctl.conf文件最后,添加以下内容: fs.file-max = 6553600 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 1024 65000 net.core.rmem_default = 4194304 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 262144 这里的“fs.file-max = 6553600”其实是由“fs.file-max = 512 * PROCESSES”得到的,我们指定PROCESSES的值为12800,即为“fs.file-max =512 *12800”。 sysctl.conf文件修改完毕后,接着执行“sysctl -p”使设置生效。10,更改字符集,支持中文,但是建议还是用英文字符 防止乱码
解决中文问题 [liuwei@centos6 ~]$ vi /etc/sysconfig/i18n 改成这个 LANG=zh_CN.UTF-8 [liuwei@centos6 ~]$source /etc/sysconfig/i18n11.锁定关键系统文件
chattr +i /etc/passwd /etc/group /etc/gshadow /etc/inittab [root@centos6 ~]# chattr +i /etc/passwd /etc/shadow 给这个两个文件加上锁 [root@centos6 ~]# useradd liu useradd: cannot open /etc/passwd [root@centos6 ~]# chattr -i /etc/passwd /etc/shadow 给这个两个文件加解锁 [root@centos6 ~]# useradd liu [root@centos6 ~]# chattr -i /etc/passwd /etc/shadow 把这个加锁命令移动一下【因为大家都知道这个是解锁的命令】 -bash: /usr/bin/chattr: 没有那个文件或目录 [root@centos6 ~]# mv /usr/bin/liuwei /usr/bin/chattr
范例:
# chattr +i .bash_logout ——>添加一个隐藏的“i”属性,后面再细讲
#lsattr -a ——>将当前目录的文件或目录下的文件所有属性(包括隐藏属性)列出
-------------- ./.
-------------- ./..
---i---------- ./.bash_logout
-------------- ./.bash_profile
-------------- ./.bashrc12,清空 /etc/issue ,去除系统以及内核版本登录前的版本提示
[root@centos6 ~]# > /etc/issue 隐藏系统的版本信息 [root@centos6 ~]#13.实战经验分享(属用性能调优)
Linux 用户线程数限制导致的 java.lang.OutOfMemoryError: unable to create new native thread
异常,需要做以下优化,把普通用户创建线程数调大一点(更加实际需求调整)如果没有调整默认普通用户是1024(太小了)# vi /etc/security/limits.d/90-nproc.conf # Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. root soft nproc unlimited * soft nproc 20480
相关文章推荐
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux运维学习笔记之四:安装后的基本调优及安全设置(系统基础优化)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- Linux系统基础优化脚本--安装完操作系统必做的操作
- 实践生产服务器环境最小化安装后 Centos 6.5 优化 一些基础优化和安全设置
- XP系统下用虚拟机安装centos 5.6(Linux系统)图文教程(二)—“linux优化配置”
- centos 5.6 linux安装系统后的基本优化
- Linux系统基础优化14条总结(CentOS6.5)
- Linux运维二:CentOS6.6系统安装后的基本配置与优化
- Centos6.5 64linux系统基础优化(一)
- Linux学习之CentOS(三十)--SELinux安全系统基础
- CentOS6.4系统安装后的基础优化
- CentOS6.4系统安装后的基础优化
- CentOS Linux下MySQL 5.1.x的安装、优化和安全配置
- CentOS系统安装后的基础优化
- CentOS6.4系统安装后的基础优化