確認SELinux狀態
使用命令 getenforce 或 sestatus 查看當前模式(Enforcing/Permissive/Disabled)。
臨時禁用SELinux
執行 sudo setenforce 0 切換為Permissive模式,避免策略阻止操作。
查看并分析日志
/var/log/audit/audit.loggrep -i "denied" /var/log/audit/audit.log 或 ausearch -m avc -ts recent 查找拒絕記錄。audit2why 解釋拒絕原因,audit2allow 生成自定義策略模塊。修改策略或文件上下文
restorecon -Rv /path/to/file 恢復默認上下文,或 chcon 手動修改。.te/.pp 文件,重新編譯并加載:make -f /usr/share/selinux/devel/Makefilesudo semodule -i custom_policy.pp。永久禁用(如需)
編輯 /etc/selinux/config,將 SELINUX=enforcing 改為 disabled,重啟生效。
注意: