Linux SELinux
A locked room might have a key check and a guard who checks whether the visitor is allowed to enter that kind of room. Linux has a similar extra security layer called SELinux. It checks an additional set of rules before a program can use a file or another resource. An ordinary permission can look correct while SELinux still blocks the action.
Linux's regular owner-and-permission checks are called discretionary access control (DAC). SELinux uses mandatory access control (MAC): a policy, or set of rules, can make a further allow-or-deny decision. SELinux makes decisions using security contexts, labels attached to processes, files, ports, and other objects. A context commonly includes an SELinux user, role, type, and sometimes a security level. In the targeted policy used by many distributions, a process runs in a domain and files carry types. Policy rules describe which domains may perform which operations on which types. Ownership and mode bits remain relevant; SELinux is an additional policy layer.
Use getenforce or sestatus to inspect mode and policy details. ls -Z path shows a file's security context, and ps -Z shows process contexts. Output depends on the distribution and active policy. Compare an unexpected label with the policy's default for that path instead of copying a label from another system.
In enforcing mode, SELinux can deny an operation and record an audit event. In permissive mode, it records policy denials but allows the operation to continue; this can help diagnose or develop policy, but it does not test whether enforcing mode will work without consequences. When SELinux is disabled, its policy is not loaded and it does not enforce policy; changing from disabled can require relabeling and a reboot. On systems that provide it, setenforce switches between enforcing and permissive at runtime, but that temporary change does not persist across reboot.
When an application reports "permission denied," identify the process, requested resource, and active context. Inspect the path with ls -Z and the process with ps -Z. Then look for a matching Access Vector Cache (AVC) event, for example with ausearch -m AVC,USER_AVC -ts recent when audit tools are installed. Match the event to the failing process and resource; nearby denials may be unrelated.
If a file has the wrong label, restorecon can restore the policy's default context for that path. Check the target and the tool's local options before applying changes. Nonstandard paths or applications may need a persistent file-context mapping, a policy boolean, or a dedicated rule. Use the distribution's policy guidance and test any change. A broad policy change or disabling SELinux can hide the denial without correcting its cause.




