linux(centos8):禁用selinux(临时关闭/永久关闭)

linux(centos8):禁用selinux(临时关闭/永久关闭)

一,selinux的用途

1,什么是selinux

SELinux:即安全增强型 Linux(Security-Enhanced Linux)

它是一个 Linux 内核模块,也是 Linux 的一个安全子系统

它主要由美国国家安全局开发,

它的主要作用:最大限度地减小系统中服务进程可访问的资源(最小权限原则)

2,为什么要关闭selinux?

有的软件对于selinux的安全规则支持不够好,就会建议在安装前把selinux先关闭,

例如:k8s:

附:k8s的相应说明:

Setting SELinux in permissive mode by runningsetenforce 0andsed ...effectively disables it.

This is required to allow containers to access the host filesystem, which is needed by pod networks for example.

You have to do this until SELinux support is improved in the kubelet...

其目的在于允许容器访问宿主机的文件系统,

这种情况下只能先关闭selinux

说明:如果不是要运行的软件有相应需求,不建议关闭selinux

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com本文: https://blog.imgtouch.com/index.php/2023/05/22/linuxcentos8-jin-yong-selinux-lin-shi-guan-bi-yong-jiu-guan-bi/

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,查看当前selinux的状态?

1,selinux的三种运行模式:

enforcing:强制模式,SELinux 正在运行中,已经在限制 domain/type

permissive:宽容模式:SELinux 正在运行中,但仅发出警告信息,并不会实际限制 domain/type 的存取

(permissive模式可以用在测试环境中供调试规则时使用)

disabled:关闭,SELinux 没有实际运行。

2,用sestatus查看

[liuhongdi@centos8 ~]$ sestatus -v

SELinux status: enabled

SELinuxfs mount: /sys/fs/selinux

SELinux root directory: /etc/selinux

Loaded policy name: targeted

Current mode: enforcing

Mode from config file: enforcing

Policy MLS status: enabled

Policy deny_unknown status: allowed

Memory protection checking: actual (secure)

Max kernel policy version: 31

...

可以看到: Current mode: enforcing

3,用getenforce查看(常用)

[liuhongdi@centos8 ~]$ getenforce

Enforcing

三,临时关闭/开启selinux

查看当前的运行模式

[root@centos8 liuhongdi]# getenforce

Enforcing

配置selinux运行模式为:Permissive

#0: Permissive

#1: Enforcing

[root@centos8 liuhongdi]# setenforce 0

查看效果:

[root@centos8 liuhongdi]# getenforce

Permissive

四,永久关闭selinux

1, 修改配置文件

[root@centos8 liuhongdi]# vi /etc/selinux/config

设置配置项为:

SELINUX=disabled

说明:默认值是: #SELINUX=enforcing

然后重启机器

2,修改/etc/sysconfig/selinux 这个文件也可以生效

因为它其实就是/etc/selinux/config的符号链接

[root@centos8 liuhongdi]# ll /etc/sysconfig/selinux

lrwxrwxrwx. 1 root root 17 11月 11 2019 /etc/sysconfig/selinux -> ../selinux/config

五,selinux的相关知识:

1,selinux默认的审计日志位于:/var/log/audit/audit.log

[root@centos8 ~]# ll /var/log/audit/audit.log

-rw------- 1 root root 5093679 5月 29 13:57 /var/log/audit/audit.log

2,如何分析selinux的日志?

#-a:--analyze=FILE: 分析一个文件

[root@centos8 ~]# sealert -a /var/log/audit/audit.log

3,查询系统中的布尔型规则及其状态

[root@centos8 liuhongdi]# getsebool -a

六,查看linux的版本

[liuhongdi@centos8 ~]$ cat /etc/redhat-release

CentOS Linux release 8.1.1911 (Core)

猜你喜欢

乐视1s500和501有什么区别
365bet足球网站

乐视1s500和501有什么区别

07-05 2733
WPS文字章节 自动分页
365bet足球网站

WPS文字章节 自动分页

07-19 6444
广州万圣节超全攻略|集市、电音节、派对...浪就完事了!
中国人为何一定要习武?
365bet足球网站

中国人为何一定要习武?

06-27 4756
巴士管家怎么退票?巴士管家app退票教程
《孤岛惊魂:新曙光》 图文全结局剧情流程全支线攻略 全收集品位置