CentOS-7.5 设置 selinux

CentOS-7.5 设置 selinux,第1张

实验目的:关闭 selinux 

推荐:使用 sed 方式替换

优点:快捷,效率高

使用 sed 设置 selinux  案例如下:

[root@shell ~]#

[root@shell ~]# cat  /etc/selinux/config             #查看未设置前的 Selinux 配置内容

1、永久关闭selinux

这种方式修改完配置文件以后,需要重启Linux系统才能生效

[root@shell ~]#

[root@shell ~]# sed  -i  s#SELINUX=enforcing#SELINUX=disabled#   /etc/selinux/config             #使用sed命令设置selinux为disabled状态

[root@shell ~]#

[root@shell ~]# cat  /etc/selinux/config                #查看设置后的 Selinux 配置内容

2、临时关闭selinux

[root@shell ~]#

[root@shell ~]# setenforce   0                #临时关闭,重启系统就会失效

[root@shell ~]#

[root@shell ~]# getenforce              #查看selinux的当前状态

3、使用1+2的相结合的方式

这种方式不需要重启Linux,也可使修改生效

[root@shell ~]#

[root@shell ~]# sed  -i  s#SELINUX=enforcing#SELINUX=disabled#  /etc/selinux/config            #先用sed命令进行永久关闭

[root@shell ~]# setenforce  0                        #然后再执行临时关闭

[root@shell ~]# getenforce               #查看修改结果

1. [root@localhost ~]# getenforce

如果为disabled 就是已经关闭,如果enforce 就是强制的模式

(1)不重启的头闭 [root@localhost ~]# setenforce 0 #重启电脑后失效

(2)重启电脑的关闭 [root@localhost ~]# vi /etc/selinux/config

把SELINUX=enforce 改成disabled就可以了,重启电脑,永久生效

一、SELinux三种模式简介

二、getenforce命令

功能:查看当前SELinux的运行模式

三、sestatus命令

功能:查看当前系统上面SELinux的策略,运行模式等信息

命令格式:

sestatus [-vb]

相关参数与选项:

-v:检查列于/etc/sestatus.conf内的文件御锦城的安全上下文

-b:将目前策略的规则布尔值列出,亦即某些规则是否要启动(0/1)之意

四、SELinux的配置文件(/etc/selinux/config)

SELINUX=enforcing:当前SELinux的模式

SELINUXTYPE=targeted:当前SELinux的策略

如果想要修改策略和模式,就更改这个文件里面的内容即可

五、SELinux模式的更改(setenforce命令)

SELinux模式的更改规则:

setenforce命令格式:

# 转换为Permissive宽容模式 setenforce 0

# 转换为Enforcing强制模式 setenforce 1

注意事项:setenforce无法设置SELinux为Disabled模式

六、restorecon -Rv 命令

介绍:

当你从Disabled切换为Enforcing模式时,会有一堆服务无法顺利启动,会跟你说/lib/xxx里面的数据没有权限读取,所以启动失败。原因:大多是重新写入SELinux类型时出错的缘故

解决办法:

切换为Permissive宽容模式,然后使用restorecon -Rv / 重新还原所有SELinux的类型,就能解决这个问题


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8388636.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存