2023-08-17 21:34:15 +08:00
|
|
|
# semanage fcontext
|
|
|
|
|
|
|
|
> Manage persistent SELinux security context rules on files/directories.
|
2024-05-27 23:54:20 +08:00
|
|
|
> See also: `semanage`, `matchpathcon`, `secon`, `chcon`, `restorecon`.
|
2023-08-17 21:34:15 +08:00
|
|
|
> More information: <https://manned.org/semanage-fcontext>.
|
|
|
|
|
|
|
|
- List all file labelling rules:
|
|
|
|
|
2025-04-20 00:21:53 +03:00
|
|
|
`sudo semanage fcontext {{[-l|--list]}}`
|
2023-08-17 21:34:15 +08:00
|
|
|
|
|
|
|
- List all user-defined file labelling rules without headings:
|
|
|
|
|
2025-04-20 00:21:53 +03:00
|
|
|
`sudo semanage fcontext {{[-l|--list]}} {{[-C|--locallist]}} {{[-n|--noheading]}}`
|
2023-08-17 21:34:15 +08:00
|
|
|
|
|
|
|
- Add a user-defined rule that labels any path which matches a PCRE regex:
|
|
|
|
|
2025-04-20 00:21:53 +03:00
|
|
|
`sudo semanage fcontext {{[-a|--add]}} {{[-t|--type]}} {{samba_share_t}} {{'/mnt/share(/.*)?'}}`
|
2023-08-17 21:34:15 +08:00
|
|
|
|
|
|
|
- Delete a user-defined rule using its PCRE regex:
|
|
|
|
|
2025-04-20 00:21:53 +03:00
|
|
|
`sudo semanage fcontext {{[-d|--delete]}} {{'/mnt/share(/.*)?'}}`
|
2023-08-17 21:34:15 +08:00
|
|
|
|
|
|
|
- Relabel a directory recursively by applying the new rules:
|
|
|
|
|
|
|
|
`restorecon -R -v {{path/to/directory}}`
|