首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SELinux: /etc/sysconfig/selinux还是/etc/selinux/config?

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

Server Fault用户
提问于 2020-01-15 08:01:49
回答 2查看 1.7K关注 0票数 0

我正在运行CentOS Linux7.5.1804发行版( SELinux ),并遇到了通常的set SELinux允许的任务。但是,我的两个源给了我两个应该设置配置的不同位置:

  1. /etc/sysconfig/selinux

cat /etc/sysconfig/selinux

代码语言:javascript
复制
# 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/config

cat /etc/selinux/config

代码语言:javascript
复制
# 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,这两种解决方案都有一个答案。

我现在的版本应该用哪一种?

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

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

代码语言:javascript
复制
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
EN

回答 2

Server Fault用户

回答已采纳

发布于 2020-01-15 08:10:00

在CentOS 7系统中,我必须手动操作,但是CentOS 6和Fedora 31是相同的

代码语言:javascript
复制
lrwxrwxrwx. 1 root root   17 Oct 31  2018 selinux -> ../selinux/config

看来他们是同一个文件。由于肌肉记忆,亲自使用/etc/selinx/config。

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

然后考虑一下你的系统已经“坏了”。这很容易测试,其中一个是允许的,另一个是强制的。重新启动..。

票数 3
EN

Server Fault用户

发布于 2021-11-24 05:58:07

默认的selinux配置文件在每个/etc/selinux/config中的man 8 selinux中。在RHEL 6部署指南的附录D(在RHEL7doc中找不到)中,他们提到/etc/sysconfig是到/etc/selinux/config的一个符号链接:

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

当您看到ls -la输出时,您就会知道它是一个符号链接,因为第一个字段是l,用于链接,而ugorwx

代码语言:javascript
复制
[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 19 Nov 24 00:58 selinux -> /etc/selinux/config

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

代码语言:javascript
复制
[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

如果遇到这种情况,很容易修复符号链接:

代码语言:javascript
复制
[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,一个这样我就不会在符号链接上犯另一个错误,而是两个,因为该目录中的一些配置文件在较新的版本中变得不受欢迎;例如,RHEL 8中的nfs

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/999009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档