RHEL SELinux:/etc/sysconfig/selinux 还是 /etc/selinux/config?

RHEL SELinux:/etc/sysconfig/selinux 还是 /etc/selinux/config?

我正在运行 CentOS Linux 版本 7.5.1804 (Core),遇到了通常将 SELinux 设置为 Permissive 的任务。但是我的两个来源给了我两个不同的配置设置位置:

  1. 在/etc/sysconfig/selinux中

猫/etc/sysconfig/selinux

# 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 three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
  1. 在/etc/selinux/配置

猫/etc/selinux/config

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

我读过相关的 RedHat 论坛,但似乎没人特别关注这个。另请阅读Selinux - centos - 缺少 /etc/selinux/config,两种解决方案均能给出答案。

我当前应该使用哪一个版本?

对于新版本,我应该使用哪一个?

更新:它们在我的系统中没有符号链接。实际上它们是两个完全不同的文件:

ls -la /etc/selinux/ | grep config
-rw-r--r--.  1 root root  550 Jan 14 15:55 config
ls -la /etc/sysconfig/ | grep selinux
-rw-r--r--.  1 root root  543 Jan 10 14:12 selinux

答案1

我手头有一个 CentOS 7 系统,但 CentOS 6 和 Fedora 31 是一样的

lrwxrwxrwx. 1 root root   17 Oct 31  2018 selinux -> ../selinux/config

看起来它们是同一个文件。个人使用 /etc/selinx/config,因为我有肌肉记忆。


但在我的系统中它们是不同的文件,大小不同,更改时间也不同

然后假设您的系统已“损坏”。这很容易测试,在一个系统中设置允许,在另一个系统中设置强制。重新启动...

答案2

默认的 selinux 配置文件位于/etc/selinux/configman 8 selinuxRHEL 6 部署指南(在 RHEL 7 文档中找不到),他们提到这/etc/sysconfig是一个符号链接/etc/selinux/config

/etc/sysconfig/selinux 文件包含 SELinux 的基本配置选项。它是 /etc/selinux/config 的符号链接

当您看到ls -la输出时,您就会知道它是一个符号链接,因为第一个字段将是l,表示链接,并且ugo将具有rwx

[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 19 Nov 24 00:58 selinux -> /etc/selinux/config

在我意识到这是一个符号链接之前,我意外地用它覆盖了文件,sed因为默认情况下sed不遵循符号链接:

[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 17 Jul 24 23:16 selinux -> ../selinux/config
[root@test sysconfig]# grep '^SELINUX=' selinux
SELINUX=enforcing
[root@test sysconfig]# sed -i 's/SELINUX=enforcing/SELINUX=permissive/' selinux
[root@test sysconfig]# ls -lah selinux
-rw-r--r--. 1 root root 544 Nov 24 00:50 selinux

如果你遇到这种情况,有一个简单的解决方法就是恢复符号链接:

[root@test sysconfig]# rm /etc/sysconfig/selinux
rm: remove regular file ‘/etc/sysconfig/selinux’? y
[root@test sysconfig]# ln -s /etc/selinux/config selinux
[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 19 Nov 24 00:52 selinux -> /etc/selinux/config

我个人只修改了/etc/selinux/config,一是为了避免再次犯符号链接错误,二是因为该目录中的一些配置文件在较新的版本中已被弃用;例如,nfs在 RHEL 8 中。

相关内容