未启用 SELinux

use*_*924 10 selinux

我使用以下命令在 ubuntu 上安装了 SELINUX:

sudo apt-get install selinux
Run Code Online (Sandbox Code Playgroud)

配置文件中/etc/selinux包含以下信息

SELINUX=permissive

SELINUXTYPE=default

SETLOCALDEFS=0
Run Code Online (Sandbox Code Playgroud)

但是我无法设置 selinux,当我检查使用sestatus -v command 它时会给出输出

SELINUX is disabled
Run Code Online (Sandbox Code Playgroud)

我应该如何启用我的 SELINUX?

当我使用命令时seinfo。它提供以下输出

ERROR: policydb version 26 does not match my version range 15-24
ERROR: Unable to open policy /etc/selinux/default/policy/policy.26.
ERROR: Input/output error
Run Code Online (Sandbox Code Playgroud)

check-selinux-installation 命令给出以下输出 ../proc/1 kernel..

未启用 SELinux。init 进程 (PID 1) 在错误的域中运行。/etc/pam.d/login 未启用 SELinux 未启用 FSCKFIX - 不严重,但可能会阻止系统启动... udev 将创建未正确标记的节点

请帮忙

cio*_*y23 4

此错误可能是因为您将 AppArmor 与 SELinux 一起运行。Ubuntu 中默认安装 AppArmor。您不能同时使用 2 个 LSM(Linux 安全模块)。如果您希望使用 SELinux,则需要删除 AppArmor

请参阅此处的一个问题:同时运行 SELinux 和 AppArmor 是一个坏主意吗?


mta*_*xan 2

这是一个荒谬的老问题,但它帮助我部分地追踪了我的问题,所以我添加了另一个答案。

您不仅需要像 cioby23 所说的那样删除 AppArmor,而且还需要从上游 Debian 收到一些额外的步骤,但这些步骤根本没有详细记录。以下是使用标准提供的软件包将标准 Ubuntu 系统(对我来说是 16.04.6)转换为在许可模式下使用 SELinux 的命令:

# make sure you have the most up-to-date info
apt-get update
apt-get dist-upgrade

#disable and remove apparmor
/etc/init.d/apparmor stop
apt-get remove apparmor

#install SELinux
apt-get install selinux

# install the missing dependency
apt-get install auditd

# install the activate tool required to make it work
apt-get install selinux-basics

#missing manual step to actually make SELinux work (part of selinux-basics)
selinux-activate

# need to restart for it to take effect
shutdown now
Run Code Online (Sandbox Code Playgroud)

我个人发现必须selinux-activate从上游 Debian 的讨论中手动运行(https://unix.stackexchange.com/questions/136988/whats-missing-with-my-selinux-installation)。
它解决了 PID 1 上错误上下文的确切问题,该问题也表现为错误getfilecon

EDIT1:更新语言以避免策略命名混乱。
EDIT2:拆分命令,为每个命令提供更好的描述