commands.sh

semanage fcontext

linux

Manage persistent SELinux security context rules on files/directories. See also: `semanage`, `matchpathcon`, `secon`, `chcon`, `restorecon`.

More info →

Options (6)

-l, --listboolean

List all file labelling rules

Example: sudo semanage fcontext {{[-l|--list]}}
boolean

List all user-defined file labelling rules without headings

Example: sudo semanage fcontext {{[-lCn|--list --locallist --noheading]}}
-a, --addboolean

Add a user-defined rule that labels any path which matches a PCRE `regex`

Example: sudo semanage fcontext {{[-a|--add]}} {{[-t|--type]}} {{samba_share_t}} '{{/mnt/share(/.*)?}}'
-t, --typeboolean

Add a user-defined rule that labels any path which matches a PCRE `regex`

Example: sudo semanage fcontext {{[-a|--add]}} {{[-t|--type]}} {{samba_share_t}} '{{/mnt/share(/.*)?}}'
-e, --equalboolean

Add a user-defined rule that creates a labeling equivalence between two subpaths

Example: sudo semanage fcontext {{[-a|--add]}} {{[-e|--equal]}} /{{path/to/ref}} /{{path/to/target}}
-d, --deleteboolean

Delete a user-defined rule using its PCRE `regex`

Example: sudo semanage fcontext {{[-d|--delete]}} '{{/mnt/share(/.*)?}}'

Examples (6)

List all file labelling rules

List all user-defined file labelling rules without headings

sudo semanage fcontext [-lCn|--list --locallist --noheading]

Add a user-defined rule that labels any path which matches a PCRE `regex`

sudo semanage fcontext [-a|--add] [-t|--type] samba_share_t '/mnt/share(/.*)?'

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

Delete a user-defined rule using its PCRE `regex`

sudo semanage fcontext [-d|--delete] '/mnt/share(/.*)?'

Relabel a directory recursively by applying the new rules

restorecon -Rv path/to/directory
made by @shridhargupta | data from tldr-pages