2025-03-14 21:59:59 -06:00
|
|
|
# semanage fcontext
|
|
|
|
|
|
|
|
|
|
> Manage persistent SELinux security context rules on files/directories.
|
|
|
|
|
> See also: `semanage`, `matchpathcon`, `secon`, `chcon`, `restorecon`.
|
|
|
|
|
> More information: <https://manned.org/semanage-fcontext>.
|
|
|
|
|
|
|
|
|
|
- List all file labelling rules:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`sudo semanage fcontext {{[-l|--list]}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- List all user-defined file labelling rules without headings:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`sudo semanage fcontext {{[-lCn|--list --locallist --noheading]}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-09-14 18:48:49 -06:00
|
|
|
- Add a user-defined rule that labels any path which matches a PCRE `regex`:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`sudo semanage fcontext {{[-a|--add]}} {{[-t|--type]}} {{samba_share_t}} '{{/mnt/share(/.*)?}}'`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Add a user-defined rule that creates a labeling equivalence between two subpaths:
|
|
|
|
|
|
|
|
|
|
`sudo semanage fcontext {{[-a|--add]}} {{[-e|--equal]}} /{{path/to/ref}} /{{path/to/target}}`
|
|
|
|
|
|
2025-09-14 18:48:49 -06:00
|
|
|
- Delete a user-defined rule using its PCRE `regex`:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`sudo semanage fcontext {{[-d|--delete]}} '{{/mnt/share(/.*)?}}'`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Relabel a directory recursively by applying the new rules:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`restorecon -Rv {{path/to/directory}}`
|