linux系统调优--Selinux

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/smithereensman/article/details/51352312

什么是Selinux

Selinux 全称 Security Enhanced Linux (安全强化 Linux),是 MAC (Mandatory Access Control,强制访问控制系统)的一个实现,目的在于明确的指明某个进程可以访问哪些资源(文件、网络端口等)。强制访问控制系统的用途在于增强系统抵御 0-Day 攻击(利用尚未公开的漏洞实现的攻击行为)的能力。所以它不是网络防火墙或 ACL 的替代品,在用途上也不重复。

  • DAC(Discretionary access control,自主访问控制):
    DAC机制就是指对象(比如程序、文件或进程等)的的拥有者可以任意的修改或授予此对象相应的权限。也就是大家熟悉的使用user、group和other的方式来进行权限的控制。
  • MAC(Mandatory Access Control,强制访问控制):
    MAC机制是指系统不再允许对象(比如程序、文件或文件夹等)的拥有者随意修改或授予此对象相应的权限,而是透过强制的方式为每个对象统一授予权限。

优点: 在MAC这种安全机制下,访问控制体系的限制下,进程只能访问那些在他的任务中所需要文件。并且与部分的网络服务器加以整合,如DHCP,Apacher等服务。假如使用传统的DAC方式,我们的RHEL5上有提供WEB服务的时候,那么当黑客入侵WEB服务器,那么黑客有可能提升自己的权限,从而导致整台的RHEL5的服务器瘫痪;但是如果采用了MAC的方式,由于有了SELinux的保护,当黑客入侵WEB服务器,由于进程只能访问那些在他的任务中所需要文件,也就是WEB服务器的所有文件,不能访问除WEB服务器以外的文件,那么我们的RHEL5的服务器不会瘫痪,最多也就是WEB服务器被黑客损坏,这样可以降低损失。

缺点: 因为SELinux的开发原则是基于最小权限原则。所以很多时候设计人员为程序设计时只会开放应用程序合法使用的权限。所以一旦应用程序更新使用了新的权限,才会被内核以权限不足的原因给干掉。很多应用程序会被限制

关闭selinux

  • 获取当前linux系统的selinux运行状态
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

返回结果有三种:Enforcing、Permissive 和 Disabled。Disabled 代表 selinux被禁用,Permissive 代表仅记录安全警告但不阻止可疑行为,Enforcing 代表记录警告且阻止可疑行为。

  • 临时改变selinux的运行状态
[root@localhost ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@localhost ~]# setenforce 0

该命令可以立刻改变 selinux运行状态,在 Enforcing 和 Permissive 之间切换,临时更改状态,结果保持至关机。一个典型的用途是看看到底是不是 selinux 导致某个服务或者程序无法运行。若是在 setenforce 0 之后服务或者程序依然无法运行,那么就可以肯定不是 selinux 导致的。此方法属于热更改策略,无需重启服务。

  • 永久改变selinux的运行状态

    更改selinux的配置文件,此方法需要重启服务,影响用户使用。以下给出两种更改配置文件的方法。

[root@localhost ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[root@localhost ~]# vi /etc/selinux/config 

将SELINUX=enforcing改为disabled

[root@localhost ~]# sed "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

提示:修改配置selinux后,要想其生效,必须重启系统。因此,可以配合setenforce 0临时关闭,无需立刻重启服务器,在生产环境不能随便关闭服务器的情况下,可以使用这种方法。

猜你喜欢

转载自blog.csdn.net/smithereensman/article/details/51352312