RHEL SELinux:/etc/sysconfig/selinux 或 /etc/selinux/config?

RHEL SELinux:/etc/sysconfig/selinux 或 /etc/selinux/config?

我正在運行 CentOS Linux 版本 7.5.1804(核心),並遇到了通常將 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/config

貓 /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,兩種解決方案都可以找到答案。

我目前的版本應該使用哪一個?

對於新版本,我應該使用哪一個?

更新:它們在我的系統中沒有符號連結。在 fat 中,它們是兩個相當不同的檔案:

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/configper man 8 selinux.在附錄 D 中RHEL 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 中。

相關內容