欢迎来到我的博客园

Linux SELinux 介绍

SELinux介绍

SELinux是 Security-Enhanced Linux (SELinux) 缩写,由NSA组织指定的一套linux上的权限规则。(NSA is short for National Security Agency )

SELinux是一种Linux操作系统中灵活控制权限的实现方式。SELinux 为应用程序,进程和文件系统的文件等定义访问权限。SELinux使用的安全规则,会定义哪些可以被访问,哪些不能被访问。

当一个进程或应用程序发起对一个对象的请求:例如文件,SELinux会检查AVC(access vector cache)中,查看该对象的缓存信息是否允许被访问。

如果SELInux无法从AVC判断,会发送请求到安全服务器,进行进一步的检查。 如果没有权限访问,会在/var/log.messges文件中输出信息“avc.denied”的日志信息

 关于SELinux详细说明的文章: SELinux Wiki (selinuxproject.org)

SELinux配置

查看SELinux模式

getenforce 命令获取当前SELinux的模式
setlinuxenabled 脚本来判断selinux是否开启,0表示SELinux已开启,1表示SELinux关闭状态
 
[root@node1 ~]# getenforce
Disabled
[root@node1 ~]# selinuxenabled
[root@node1 ~]# echo $?
1
[root@node1 ~]#

 

sestatus 查看当前selinux的状态

[root@node1 sbin]# sestatus --help
sestatus: invalid option -- '-'

Usage: sestatus [OPTION]

  -v  Verbose check of process and file contexts.
  -b  Display current state of booleans.

Without options, show SELinux status.
[root@node1 sbin]#

[root@node1 sbin]# sestatus 
SELinux status:                 disabled

 

 

修改SELinux模式

临时修改SELinux模式

setenforce  临时修改SELinux的运行模式。
setenforce Enforcing或者1。表示修改SELinux运行状态为enforcing模式。即执行模式。
setenforce Permissive或0。表示修改SELinux运行状态为permissive模式。即宽容模式。
 
SYNOPSIS
       setenforce [Enforcing|Permissive|1|0]

DESCRIPTION
       Use Enforcing or 1 to put SELinux in enforcing mode.
       Use Permissive or 0 to put SELinux in permissive mode.

  

永久修改SELinux模式

SELinux 的配置文件为/etc/selinux/config.我们可以通过修改该文件来永久开启或停止SELinux.修改文件后,需要重启系统才能生效。

SELINUX=enforcing|permissive|disabled 三个选项,第一个选项enforcing为SELinux开启,第二个选项permissive选项只打印警告信息,第三个选项disabled 关闭selinux policy.

注意:修改文件,不会立马生效,只有在下次重启才会生效.

# 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.

  

 

posted @ 2022-07-12 08:50  panzq  阅读(118)  评论(0编辑  收藏  举报