centos:开启和关闭selinux
5.4. Enabling and Disabling SELinux
Use the
/usr/sbin/getenforce
or/usr/sbin/sestatus
commands to check the status of SELinux. Thegetenforce
command returnsEnforcing
,Permissive
, orDisabled
. Thegetenforce
command returnsEnforcing
when SELinux is enabled (SELinux policy rules are enforced):$ /usr/sbin/getenforce
EnforcingThe
getenforce
command returnsPermissive
when SELinux is enabled, but SELinux policy rules are not enforced, and only DAC rules are used. Thegetenforce
command returnsDisabled
if SELinux is disabled.The
sestatus
command returns the SELinux status and the SELinux policy being used:$ /usr/sbin/sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 23
Policy from config file: targeted
SELinux status: enabled
is returned when SELinux is enabled.Current mode: enforcing
is returned when SELinux is running in enforcing mode.Policy from config file: targeted
is returned when the SELinux targeted policy is used.
5.4.1. Enabling SELinux
On systems with SELinux disabled, the
SELINUX=disabled
option is configured in/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=targetedAlso, the
getenforce
command returnsDisabled
:$ /usr/sbin/getenforce
Disabled
To enable SELinux:
Use the
rpm -qa | grep selinux
,rpm -q policycoreutils
, andrpm -qa | grep setroubleshoot
commands to confirm that the SELinux packages are installed. This guide assumes the following packages are installed: selinux-policy-targeted, selinux-policy, libselinux, libselinux-python, libselinux-utils, policycoreutils,setroubleshoot, setroubleshoot-server, setroubleshoot-plugins. If these packages are not installed, as the Linux root user, install them via theyum install
command. The following packages are optional:policycoreutils-gui, setroubleshoot, selinux-policy-devel, and mcstrans.package-name
Before SELinux is enabled, each file on the file system must be labeled with an SELinux context. Before this happens, confined domains may be denied access, preventing your system from booting correctly. To prevent this, configure
SELINUX=permissive
in/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=permissive
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targetedAs the Linux root user, run the
reboot
command to restart the system. During the next boot, file systems are labeled. The label process labels all files with an SELinux context:*** Warning -- SELinux targeted policy relabel is required.
*** Relabeling could take a very long time, depending on file
*** system size and speed of hard drives.
****Each
*
character on the bottom line represents 1000 files that have been labeled. In the above example, four*
characters represent 4000 files have been labeled. The time it takes to label all files depends upon the number of files on the system, and the speed of the hard disk drives. On modern systems, this process can take as little as 10 minutes.In permissive mode, SELinux policy is not enforced, but denials are still logged for actions that would have been denied if running in enforcing mode. Before changing to enforcing mode, as the Linux root user, run the
grep "SELinux is preventing" /var/log/messages
command as the Linux root user to confirm that SELinux did not deny actions during the last boot. If SELinux did not deny actions during the last boot, this command does not return any output. Refer to Chapter 7, Troubleshooting for troubleshooting information if SELinux denied access during boot.If there were no denial messages in
/var/log/messages
, configureSELINUX=enforcing
in/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=targetedReboot your system. After reboot, confirm that the
getenforce
command returnsEnforcing
:$ /usr/sbin/getenforce
EnforcingAs the Linux root user, run the
/usr/sbin/semanage login -l
command to view the mapping between SELinux and Linux users. The output should be as follows:Login Name SELinux User MLS/MCS Range __default__ unconfined_u s0-s0:c0.c1023
root unconfined_u s0-s0:c0.c1023
system_u system_u s0-s0:c0.c1023
If this is not the case, run the following commands as the Linux root user to fix the user mappings. It is safe to ignore the SELinux-user
warnings if they occur, where username
is already definedusername
can beunconfined_u
, guest_u
, or xguest_u
:
/usr/sbin/semanage user -a -S targeted -P user -R "unconfined_r system_r" -r s0-s0:c0.c1023 unconfined_u
/usr/sbin/semanage login -m -S targeted -s "unconfined_u" -r s0-s0:c0.c1023 __default__
/usr/sbin/semanage login -m -S targeted -s "unconfined_u" -r s0-s0:c0.c1023 root
/usr/sbin/semanage user -a -S targeted -P user -R guest_r guest_u
- /usr/sbin/semanage user -a -S targeted -P user -R xguest_r xguest_u
5.4.2. Disabling SELinux
To disable SELinux, configure
SELINUX=disabled
in/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=targetedReboot your system. After reboot, confirm that the
getenforce
command returnsDisabled
:$ /usr/sbin/getenforce
Disabled
centos:开启和关闭selinux的更多相关文章
- CentOS 7.X 关闭SELinux
1.查看 [root@dev-server ~]# getenforce Disabled [root@dev-server ~]# /usr/sbin/sestatus -v SELinux sta ...
- centos 6.X 关闭selinux
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统.在这种访问控制体系的限制下,进程只能访问那 ...
- CentOS开启和关闭防火墙
CentOS Linux开启和关闭防火墙命令有两种,一种是临时的,重启即复原:另外一种是永久性的,重启不会复原. 1) 临时生效,重启后复原 开启: service iptables start ...
- Centos 7.6关闭selinux
查看selinux状态 [root@localhost ~]# sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SE ...
- Linux下开启关闭SeLinux
SELinux (Security-Enhanced Linux) in Fedora is an implementation of mandatory access control in the ...
- 查看/关闭SElinux (原创帖,转载请注明出处)
查看SELinux状态: 1 /usr/sbin/sestatus -v | grep "SELinux status:" ##如果SELinux status参数为enabl ...
- centos7防火墙以设置以及关闭selinux
一.CentOS 7.X 关闭SELinux 1.查看 getenforce permissive 或者 enforcing模式 2.临时设置 setenforce 1 成为permissive模式 ...
- 查看SELinux状态及关闭SELinux
查看SELinux状态: 输入:/usr/sbin/sestatus -v SELinux status: enabled ##开启状态 关闭SELinux 修改vi /etc/s ...
- centos 7.0 查看selinux状态|关闭|开启
Linux在安装好之后通常SELinux都是出于默认开启的状态,开启的情况下会导致一些服务的安装不成功. 在不需要的情况下完全可以关闭掉,下面是在centos 7.0里面如何查看,关闭selinux. ...
随机推荐
- 开始一个Android的appium实例
1.查看Android的应用包名和activity的方法 (网上有很多种方法,这里应用的是查看日志的方法) CMD中输入>adb logcat -c ...
- 第五章 二叉树(c)二叉树
- Python oct() 函数
Python oct() 函数 Python 内置函数 描述 oct() 函数将一个整数转换成8进制字符串. 语法 oct 语法: oct(x) 参数说明: x -- 整数. 返回值 返回8进制字符 ...
- C++ 静态数据成员和静态成员函数
一 静态数据成员: 1.静态数据成员的定义. 静态数据成员实际上是类域中的全局变量.所以,静态数据成员的定义(初始化)不应该被放在头文件中,因为这样做会引起重复定义这样的错误.即使加上#ifndef ...
- 性能测试需求分析 业务PV量,响应时间、QPS、TPS
一. 性能测试需求分析 1.1 性能测试需求内容 性能测试需求应包括以下内容: a) 测试场景及用例,用例访问URL: b) 目标接口方法的入参.出参: c) 外部依赖的服务 ...
- nginx 的 upstream timed out 问题
nginx 作为负载服务,表现为网站访问很慢,有些文件或页面要等待到60s才会返回,我注意到60s就是超时时间,但是超时后返回状态是正常值200,网站可以正常打开,就是会一直等待到超时才打开,而且问题 ...
- Python中类的定义与使用
目标: 1.类的定义 2.父类,子类定义,以及子类调用父类 3.类的组合使用 4.内置功能 1.类的定义 代码如下: #!/usr/bin/env python #coding:utf8 class ...
- js 递归调用
js递归调用 function fact(num) { ) { ; } else { ); } } 以下代码可导致出错: var anotherFact = fact; fact = null; al ...
- JFinal WEB MVC和Struts简要对比
JFinal遵循COC原则,零配置,无xml,而struts需要配置来支持action.result.interceptor配置与使用. JFinal开发效率非常之高,相对Struts开发效率能提升五 ...
- Scrum使用心得 【转】
原文链接: http://blog.sina.com.cn/s/blog_58db96bc0100ymuk.html 1 Scrum管理模式和传统管理模式的区别 这些管理模式本质上目的相同: ...